Skip to content

Commit 14cf635

Browse files
committed
refactor: define a default CMD handler as handler.main
1 parent 1694512 commit 14cf635

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ ARG HTTP_CLI_VERSION
5858

5959
COPY task/helpers.sh helpers.sh
6060

61+
CMD ["handler.main"]
62+
6163
LABEL org.opencontainers.image.title="lambda-shell-runtime:tiny"
6264
LABEL org.opencontainers.image.version="${VERSION}"
6365
LABEL org.opencontainers.image.http_cli_version="${HTTP_CLI_VERSION}"

README.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Custom AWS Lambda runtime for executing Bash functions as serverless application
2323

2424
```bash
2525
# handler.sh
26-
hello() {
26+
main () {
2727
local event="$1"
2828
echo '{"message": "Hello from Bash Lambda!", "input": '"$event"'}'
2929
}
@@ -142,6 +142,7 @@ aws lambda create-function \
142142
--code ImageUri=123456789012.dkr.ecr.region.amazonaws.com/my-lambda:latest \
143143
--role arn:aws:iam::123456789012:role/lambda-execution-role \
144144
--package-type Image \
145+
--architectures arm64 \
145146
--timeout 30
146147
```
147148

@@ -161,17 +162,14 @@ resource "aws_lambda_function" "bash_function" {
161162

162163
### Using Lambda Runtime Interface Emulator
163164

164-
```bash
165-
# Download RIE (one time setup)
166-
mkdir -p ~/.aws-lambda-rie
167-
curl -Lo ~/.aws-lambda-rie/aws-lambda-rie \
168-
https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie
169-
chmod +x ~/.aws-lambda-rie/aws-lambda-rie
165+
https://github.com/aws/aws-lambda-runtime-interface-emulator/
166+
167+
The emulator is already available on the image, you just need to override the `entrypoint` to run test your lambda locally
170168

169+
```
171170
# Run your function locally
172171
docker run --rm -p 9000:8080 \
173-
-v ~/.aws-lambda-rie:/aws-lambda \
174-
-e HANDLER="handler.hello" \
172+
--env _HANDLER="handler.hello" \
175173
--entrypoint /aws-lambda/aws-lambda-rie \
176174
my-lambda:latest /var/runtime/bootstrap
177175
@@ -180,15 +178,6 @@ curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" \
180178
-d '{"name": "World"}'
181179
```
182180

183-
### Debug Mode
184-
185-
```bash
186-
# Run with debug output
187-
docker run --rm -p 9000:8080 \
188-
-e HANDLER="handler.hello" \
189-
-e _LAMBDA_RUNTIME_DEBUG=1 \
190-
my-lambda:latest
191-
```
192181

193182
## Building from Source
194183

@@ -239,8 +228,8 @@ The shell runtime is **highly competitive** with official runtimes while providi
239228

240229
**Function not found:**
241230
```bash
242-
# Ensure your function is defined and handler matches
243-
HANDLER="handler.my_function" # filename.function_name
231+
# Ensure your function is defined and you override
232+
# the CMD hander.my_function
244233
```
245234

246235
**Permission errors:**

task/handler.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/sh
22

3-
function f () {
3+
function main () {
44
EVENT="$1"
55
echo "$EVENT" | jq
66
echo "Default handler — override this in your runtime build context." >&2
7-
# exit 1
87
}

test/functions.sh

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,28 @@
33
VARIANT=${VARIANT:-"tiny"}
44
HANDLER=${HANDLER:-"handler.f"}
55

6-
# Setup the AWS Lambda Runtime Interface Emulator
6+
TAG="lambda-shell-runtime-${VARIANT}"
7+
8+
# The AWS Lambda Runtime Interface Emulator is already available
79
# https://github.com/aws/aws-lambda-runtime-interface-emulator/
8-
em () {
9-
mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie \
10-
https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie-arm64 \
11-
&& chmod +x ~/.aws-lambda-rie/aws-lambda-rie
12-
}
10+
1311

1412
# Start the Lambda shell container
1513
# Optionally:
1614
#
1715
# * add --detach flag to run the container in the background
1816
# * mount --volume ./task/handler.sh:/var/task/handler.sh
17+
# * set the _HANDLER environent variable
18+
1919
r () {
20-
docker run --rm \
20+
docker run \
21+
--rm \
2122
--detach \
22-
-p 9000:8080 \
23-
--name lambda-shell-runtime \
2423
--platform linux/arm64 \
25-
-v ~/.aws:/root/.aws:ro \
26-
--volume ~/.aws-lambda-rie:/aws-lambda \
27-
--entrypoint /aws-lambda/aws-lambda-rie \
28-
--env HANDLER="$HANDLER" \
29-
"lambda-shell-runtime:$VARIANT" \
24+
--entrypoint /usr/local/bin/aws-lambda-rie \
25+
-p 9000:8080 \
26+
--name "$TAG" \
27+
"$TAG" \
3028
/var/runtime/bootstrap
3129
}
3230

0 commit comments

Comments
 (0)