-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
325d48c
commit bbd243d
Showing
14 changed files
with
118 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM public.ecr.aws/lambda/nodejs:20 | ||
|
||
# Copy function code | ||
COPY dist ${LAMBDA_TASK_ROOT}/dist | ||
COPY package.json package-lock.json ${LAMBDA_TASK_ROOT} | ||
|
||
# Install NPM dependencies for function | ||
RUN npm install --omit=dev | ||
|
||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) | ||
# CMD [ "dist/addition.handler" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
cd $(dirname $0)/.. | ||
|
||
docker-compose -f compose.local.yaml logs -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
cd $(dirname $0)/.. | ||
|
||
docker-compose run --rm install | ||
docker-compose run --rm compile | ||
docker-compose -f compose.local.yaml build | ||
docker-compose -f compose.local.yaml up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
cd $(dirname $0)/.. | ||
|
||
docker-compose -f compose.local.yaml down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: '3.9' | ||
services: | ||
# curl -XPOST "http://localhost:9001/2015-03-31/functions/function/invocations" -d '{"a":2,"b":3}' | ||
addition: | ||
build: . | ||
ports: | ||
- '9001:8080' | ||
command: dist/addition.handler | ||
|
||
# curl -XPOST "http://localhost:9002/2015-03-31/functions/function/invocations" -d '{"a":5,"b":3}' | ||
subtraction: | ||
build: . | ||
ports: | ||
- '9002:8080' | ||
command: dist/subtraction.handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,7 @@ services: | |
test: | ||
<<: *base | ||
command: npm test | ||
|
||
compile: | ||
<<: *base | ||
command: npm run compile |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Callback, Context } from 'aws-lambda'; | ||
import { handler } from './addition'; | ||
|
||
describe('addition', () => { | ||
describe('handler', () => { | ||
test('2 and 3 adds up to 5', async () => { | ||
await expect(handler({a: 2, b: 3}, {} as Context, {} as Callback)).resolves.toEqual(5); | ||
}); | ||
|
||
test('invalid event structure', async () => { | ||
await expect(handler({a: 2}, {} as Context, {} as Callback)).rejects.toThrow(); | ||
}); | ||
|
||
test('invalid data types', async () => { | ||
await expect(handler({a: 'x', b: 'y'}, {} as Context, {} as Callback)).rejects.toThrow(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Handler } from 'aws-lambda'; | ||
|
||
export const handler: Handler = async (event) => { | ||
if ('a' in event && typeof event['a'] == 'number' | ||
&& 'b' in event && typeof event['b'] == 'number') { | ||
return event['a'] + event['b']; | ||
} else { | ||
throw new Error('event doesn\'t satisfy the type { a: number, b: number }'); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Callback, Context } from 'aws-lambda'; | ||
import { handler } from './subtraction'; | ||
|
||
describe('subtraction', () => { | ||
describe('handler', () => { | ||
test('2 take away 3 returns -1', async () => { | ||
await expect(handler({a: 2, b: 3}, {} as Context, {} as Callback)).resolves.toEqual(-1); | ||
}); | ||
|
||
test('invalid event structure', async () => { | ||
await expect(handler({a: 2}, {} as Context, {} as Callback)).rejects.toThrow(); | ||
}); | ||
|
||
test('invalid data types', async () => { | ||
await expect(handler({a: 'x', b: 'y'}, {} as Context, {} as Callback)).rejects.toThrow(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Handler } from 'aws-lambda'; | ||
|
||
export const handler: Handler = async (event) => { | ||
if ('a' in event && typeof event['a'] == 'number' | ||
&& 'b' in event && typeof event['b'] == 'number') { | ||
return event['a'] - event['b']; | ||
} else { | ||
throw new Error('event doesn\'t satisfy the type { a: number, b: number }'); | ||
} | ||
}; |