Skip to content

Commit 671a666

Browse files
committed
feat: add new real life example and refactor repository layout
1 parent c71c122 commit 671a666

File tree

13 files changed

+329
-80
lines changed

13 files changed

+329
-80
lines changed

Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ RUN dnf install -y jq python3 python3-libs && \
3232
COPY --from=builder /aws-cli-bin/aws /usr/local/bin/aws
3333
COPY --from=builder /aws-cli /usr/local/aws-cli
3434

35-
# Fix Python shared library path for AWS CLI v2
36-
RUN find /usr -name "libpython3*.so*" -exec cp {} /usr/local/bin/ \; 2>/dev/null || true
37-
38-
3935
# Copy http-cli
4036
COPY --from=builder /http-cli-bin/http-cli /var/task/bin/http-cli
4137

@@ -46,4 +42,4 @@ RUN chmod +x /var/runtime/bootstrap
4642

4743
WORKDIR /var/task
4844

49-
COPY functions/handler.sh handler.sh
45+
COPY task/handler.sh handler.sh

README.md

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,58 @@ Implement AWS Lambda functions in Bash, packaged as OCI-compliant container imag
66

77
Inspired by: https://docs.aws.amazon.com/lambda/latest/dg/runtimes-walkthrough.html
88

9-
## Runtime Variants
109

11-
Each runtime variant has its own Dockerfile:
10+
This custom Lambda runtime enables Bash-based execution with minimal dependencies. We provide three image variants tailored to different needs:
1211

13-
- `tiny`: [`jq`](https://stedolan.github.io/jq/) + [`http-cli`](https://github.com/ql4b/http-cli)
14-
- `slim`: same as `tiny` + AWS CLI v1
15-
- `full`: same as `slim` + AWS CLI v2
12+
## Runtime Image Variants
1613

17-
### Build locally
14+
### 1. `tiny`
15+
- Includes: `jq`, `curl`
16+
- Use case: Lightweight data parsing and HTTP requests.
1817

19-
```bash
20-
# Build tiny
21-
docker build -f tiny.Dockerfile -t lambda-shell-runtime:tiny .
18+
### 2. `micro`
19+
- Based on: `tiny`
20+
- Adds: `awscurl`
21+
- Use case: AWS API calls using IAM credentials without full AWS CLI.
22+
23+
### 3. `full`
24+
- Based on: `tiny`
25+
- Adds: **full AWS CLI** (official install)
26+
- Use case: Complete access to AWS CLI features.
27+
- Note: Previously experimented with intermediate setups (e.g., stripped-down AWS CLI), but they proved unstable. This variant now uses the official, standard installation of the AWS CLI.
2228

23-
# Build slim
24-
docker build -f slim.Dockerfile -t lambda-shell-runtime:slim .
29+
---
2530

26-
# Build full
27-
docker build -f Dockerfile -t lambda-shell-runtime:full .
31+
Each image is built from the same base but optimized for different tasks. You can choose the right variant for your Lambda depending on the environment and tools required.
32+
33+
Each runtime variant has its own Dockerfile:
34+
35+
## Local build process
36+
37+
To run the script locally:
38+
39+
```
40+
./build --platform linux/arm64 --tag your-repo/lambda-shell --load micro
2841
```
2942

43+
```
44+
./build --platform linux/arm64 --tag your-repo/lambda-shell --push micro
45+
```
46+
47+
Key Features:
48+
49+
* Platform targeting: Defaults to linux/arm64, which is suitable for AWS Lambda ARM-based functions.
50+
* Variants: You can build one or more of the supported variants: tiny, micro, or full.
51+
* Secrets: Supports injecting a GitHub token via --secret id=github_token,env=GITHUB_TOKEN for private dependency access during build.
52+
53+
Modes:
54+
* `--load` (default): Loads the image into the local Docker engine.
55+
* `--push`: Pushes the image to a remote registry.
56+
57+
## GitHub Actions Build
58+
59+
In a GitHub Actions environment, the build script is typically used in combination with Docker Buildx and secrets configured in the CI pipeline.
60+
3061
## Usage
3162

3263
To use this runtime in your own Lambda container image:

build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ TAG="lambda-shell-runtime"
1010
# VARIANTS="tiny slim full"
1111
VARIANTS="tiny micro"
1212

13-
1413
# Parse arguments
1514
while [ $# -gt 0 ]; do
1615
case "$1" in

examples/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# FROM ghcr.io/ql4b/lambda-shell-runtime:0.1.0-develop.10-full
22
FROM lambda-shell-runtime:micro
33
# FROM ghcr.io/ql4b/lambda-shell-runtime:0.1.0-develop.10-slim
4+
FROM ghcr.io/ql4b/lambda-shell-runtime:0.1.0-develop.11-tiny
45

56
WORKDIR /var/task
67

7-
COPY service.sh handler.sh
8+
RUN dnf install -y util-linux && \
9+
cp /usr/bin/uuidgen /var/task/bin/ && \
10+
dnf remove -y util-linux && \
11+
dnf clean all
12+
13+
COPY ./rrelay.sh handler.sh

examples/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
## buld
44

55
```bash
6-
CONTAINER="shell-booking"
6+
# CONTAINER="shell-booking"
77
# TAG="shell-booking:dev"
8-
TAG="703177223665.dkr.ecr.eu-central-1.amazonaws.com/ql4b-farecrumbs:booking"
8+
# TAG="703177223665.dkr.ecr.eu-central-1.amazonaws.com/ql4b-farecrumbs:booking"
9+
CONTAINER="rrlelay"
10+
TAG="rrlelay:dev"
11+
912

1013
b () {
1114
docker build \
12-
--no-cache \
1315
--platform linux/arm64 \
1416
-t "$TAG" \
1517
--secret id=github_token,env=GITHUB_TOKEN \
@@ -23,6 +25,7 @@ r () {
2325
--platform linux/arm64 \
2426
-v ~/.aws:/root/.aws:ro \
2527
--volume ~/.aws-lambda-rie:/aws-lambda \
28+
--volume ./rrelay.sh:/var/task/hander.sh:rw \
2629
--entrypoint /aws-lambda/aws-lambda-rie \
2730
--env HANDLER="handler.booking" \
2831
"$TAG" \

examples/rrelay.sh

Lines changed: 228 additions & 0 deletions
Large diffs are not rendered by default.

examples/run

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
source $(realpath $(dirname $0))/rrelay.sh
4+
5+
request='{"adults":1,"children":1,"infants":1,"teens":0,"origin":"NAP","destination":"BCN","dateOut":"2025-07-13"}'
6+
echo $request >&2
7+
correlation_id=$(uuidgen | tr '[:upper:]' '[:lower:]')
8+
# export USER_AGENT=$(randua)
9+
10+
11+
departureDate=$(echo "$request" | jq -r '.dateOut +"T00:00:00.000"')
12+
# echo "$departureDate" >&2
13+
14+
flight=$(availability "$request" \
15+
| jq --arg dateOut "$departureDate" '.trips[].dates[]|select(.dateOut == $dateOut).flights|first|del(.segments)'
16+
)
17+
# {"faresLeft":4,"flightKey":"FR~ 59~ ~~NAP~07/10/2025 15:40~BCN~07/10/2025 17:40~~","infantsLeft":16,"regularFare":{"fareKey":"VES4L3AY6V7QCEKP25YZQOZOZFWRY6UDQRC75USHLWWP46O6ECSN3JO4DDEUY7PI6ZAYZLISSNP4PT65R2P2ARTBKRII4CWGMYQKF4XU5WT37LIAC6LWDC332SPT64QR3GVVX53FTHOJNJMUUVQHXIUMHUVE6N3XE3O7NOLV4B4LZPUNAUC6U7O3ZSFR246HBE4CAXKCCXWOHC45UGVSGFR4WCXUGBKVKW54IAFFT6EXQYIWSKSFUHLX2ESS3AYRWPRKDLH22KKRDX7HDT4XRZEEJZMLX5BS2WQ6M5ORROOZJ3FMAWVPPDOP3GY742C2OZDU5IEDFB3YAFOJPHSTPDAIG3IW6YDTHMNCHGI","fares":[{"type":"ADT","amount":197.99,"count":1,"hasDiscount":false,"publishedFare":197.99,"discountInPercent":0,"hasPromoDiscount":false,"discountAmount":0.0,"hasBogof":false,"isPrime":false}]},"operatedBy":"","isSSIMLoad":false,"flightNumber":"FR 59","time":["2025-07-10T15:40:00.000","2025-07-10T17:40:00.000"],"timeUTC":["2025-07-10T13:40:00.000Z","2025-07-10T15:40:00.000Z"],"duration":"02:00"}
18+
echo "$flight" | jq -c >&2
19+
20+
basketID=$(create_basket | jq -r '.data.createBasket.id')
21+
# echo "basketId:$basketID" >&2
22+
culture=$(dashed_market "$market")
23+
# echo "$culture" >&2
24+
variables=$(booking_variables "$basketID" "$request" "$flight")
25+
# echo "$variables" | jq >&2
26+
export JWT_HANDLER=$(mktemp)
27+
create_booking "$variables"
28+
echo "$JWT" >&2
29+
booking=$(commit_booking "$basketID" | jq .data.commitBooking)
30+
echo "$booking" | jq >&2
31+
data=$(catalog_products "$basketID" "$JWT")
32+
echo "$data" | jq >&2

functions/handler.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

runtime/Dockerfile

Lines changed: 0 additions & 18 deletions
This file was deleted.

runtime/bootstrap

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ do
1919
REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2)
2020

2121
# Run the handler function from the script
22-
# set -x
2322
RESPONSE=$($(echo "$HANDLER" | cut -d. -f2) "$EVENT_DATA")
24-
# set +x
23+
2524

2625
echo "$RESPONSE" | curl -sS -X POST \
2726
"http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/${REQUEST_ID}/response" \
2827
-H "Content-Type: application/json" \
2928
-d @-
30-
31-
# --data-binary "$RESPONSE"
3229
done

0 commit comments

Comments
 (0)