Skip to content

Commit dbde8fe

Browse files
committed
feat: initial Commit
0 parents  commit dbde8fe

19 files changed

+16484
-0
lines changed

.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Dockerfile
2+
docker-compose.yml
3+
*.ts
4+
**/*.ts
5+
src
6+
.husky
7+
.gitignore
8+
dev-server.js
9+
jest.config.js
10+
service-collection.postman_collection.json
11+
tsconfig.json
12+
tslint.json
13+
logs
14+
cocverage

.gitignore

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/node
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=node
4+
5+
### Node ###
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
.pnpm-debug.log*
14+
15+
# Diagnostic reports (https://nodejs.org/api/report.html)
16+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
17+
18+
# Runtime data
19+
pids
20+
*.pid
21+
*.seed
22+
*.pid.lock
23+
24+
# Directory for instrumented libs generated by jscoverage/JSCover
25+
lib-cov
26+
27+
# Coverage directory used by tools like istanbul
28+
coverage
29+
*.lcov
30+
31+
# nyc test coverage
32+
.nyc_output
33+
34+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
35+
.grunt
36+
37+
# Bower dependency directory (https://bower.io/)
38+
bower_components
39+
40+
# node-waf configuration
41+
.lock-wscript
42+
43+
# Compiled binary addons (https://nodejs.org/api/addons.html)
44+
build/Release
45+
46+
# Dependency directories
47+
node_modules/
48+
jspm_packages/
49+
50+
# Snowpack dependency directory (https://snowpack.dev/)
51+
web_modules/
52+
53+
# TypeScript cache
54+
*.tsbuildinfo
55+
56+
# Optional npm cache directory
57+
.npm
58+
59+
# Optional eslint cache
60+
.eslintcache
61+
62+
# Microbundle cache
63+
.rpt2_cache/
64+
.rts2_cache_cjs/
65+
.rts2_cache_es/
66+
.rts2_cache_umd/
67+
68+
# Optional REPL history
69+
.node_repl_history
70+
71+
# Output of 'npm pack'
72+
*.tgz
73+
74+
# Yarn Integrity file
75+
.yarn-integrity
76+
77+
# dotenv environment variables file
78+
.env
79+
.env.test
80+
.env.production
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# Serverless directories
104+
.serverless/
105+
106+
# FuseBox cache
107+
.fusebox/
108+
109+
# DynamoDB Local files
110+
.dynamodb/
111+
112+
# TernJS port file
113+
.tern-port
114+
115+
# Stores VSCode versions used for testing VSCode extensions
116+
.vscode-test
117+
118+
# yarn v2
119+
.yarn/cache
120+
.yarn/unplugged
121+
.yarn/build-state.yml
122+
.yarn/install-state.gz
123+
.pnp.*
124+
125+
### Node Patch ###
126+
# Serverless Webpack directories
127+
.webpack/
128+
app

.husky/pre-commit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
npm run prettier
4+
npm run lint
5+
npm test
6+

.husky/prepare-commit-msg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
exec < /dev/tty && node_modules/.bin/cz --hook || true
3+

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM public.ecr.aws/lambda/nodejs:14
2+
3+
COPY . ${LAMBDA_TASK_ROOT}
4+
5+
RUN npm install
6+
7+
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
8+
CMD [ "app/index.handler" ]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Balwant
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Lambda Container Service
2+
> Service template using container based lambda function
3+
4+
## Developing
5+
6+
Runs a custom dev webserver which hosts the lambda function which can be hosted on
7+
```shell
8+
$ npm start
9+
```
10+
11+
## Test
12+
13+
### Unit Tests
14+
15+
```shell
16+
$ npm run test
17+
```
18+
19+
### Integration Tests
20+
21+
#### Automated Integration Tests (WIP)
22+
Runs service using `dev-server` and tests using Newman test collection.
23+
24+
```shell
25+
$ npm run test:newman
26+
```
27+
#### Manual Test
28+
Start the environment
29+
```shell
30+
$ npm run build
31+
$ docker-compose build
32+
$ docker-compose up
33+
```
34+
In another temrinal, run:
35+
36+
```shell
37+
$ curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
38+
```
39+
40+
## Package @todo
41+
- Check if container repository exists (Creates if not exists) - Should be in pipeline helpers
42+
- npm run build
43+
- npm run package
44+
- create a release tag on Github Repo
45+
- publish image based on version specified by semantic release.
46+
47+
## Deploy @todo
48+
49+
- Deploy a version to service's lambda by updating the image to release build version.
50+
- And verify health check.

dev-server.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const express = require('express')
2+
const { handler } = require('./app/index')
3+
const newman = require('newman')
4+
5+
const app = express();
6+
const port = 9000;
7+
8+
let server = null;
9+
10+
app.post('/2015-03-31/functions/function/invocations', async (req, res) => {
11+
try {
12+
const body = req.body ? JSON.parse(req.body) : req;
13+
handler(body, {}).then(result => {
14+
res.send(result);
15+
}).catch(error => console.error(error));
16+
} catch(error) {
17+
console.error(error);
18+
}
19+
})
20+
21+
app.all('/api', async (req, res) => {
22+
handler(req, {}).then(result => {
23+
res.send(result);
24+
}).catch(error => console.error(error));
25+
});
26+
27+
server = app.listen(port, () => {
28+
console.log(`
29+
Example app listening at:
30+
POST http://localhost:${port}/2015-03-31/functions/function/invocations
31+
`);
32+
33+
if (process.argv[2]) {
34+
const testFilename = process.argv[3] || 'service-collection.postman_collection.json'
35+
36+
console.log('Running Newman tests');
37+
if (!existsSync(`./${testFilename}`)) {
38+
console.error(`Error: test collection not found
39+
./${testFilename}
40+
41+
Skipping tests. Running dev server only.
42+
`);
43+
44+
return;
45+
}
46+
console.log('Test collection:', testFilename);
47+
48+
newman.run({
49+
collection: require(`./${testFilename}`),
50+
reporters: 'cli',
51+
},
52+
(err, summary) => {
53+
if (err) {
54+
console.log(err);
55+
process.exit(1)
56+
}
57+
process.exit();
58+
})
59+
}
60+
})

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3.3'
2+
services:
3+
app.handler:
4+
ports:
5+
- '9000:8080'
6+
build: .
7+
volumes:
8+
- .://var/task/

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

0 commit comments

Comments
 (0)