Skip to content

Commit 08db91c

Browse files
committed
feat: micro runtime image uses awscurl instead of aws-cli
1 parent 767e963 commit 08db91c

File tree

5 files changed

+88
-4
lines changed

5 files changed

+88
-4
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ jobs:
3535
echo "${{ secrets.GHCR_PAT }}" > github_token
3636
export DOCKER_BUILDKIT=1
3737
docker buildx build --builder default --platform linux/arm64 --output type=docker --progress=plain --secret id=github_token,src=github_token -t lambda-shell-runtime:tiny -f tiny.Dockerfile .
38-
docker buildx build --builder default --platform linux/arm64 --output type=docker --progress=plain --secret id=github_token,src=github_token -t lambda-shell-runtime:slim -f slim.Dockerfile .
39-
docker buildx build --builder default --platform linux/arm64 --output type=docker --progress=plain --secret id=github_token,src=github_token -t lambda-shell-runtime:full -f Dockerfile .
38+
docker buildx build --builder default --platform linux/arm64 --output type=docker --progress=plain --secret id=github_token,src=github_token -t lambda-shell-runtime:micro -f micro.Dockerfile .
39+
# docker buildx build --builder default --platform linux/arm64 --output type=docker --progress=plain --secret id=github_token,src=github_token -t lambda-shell-runtime:slim -f slim.Dockerfile .
40+
# docker buildx build --builder default --platform linux/arm64 --output type=docker --progress=plain --secret id=github_token,src=github_token -t lambda-shell-runtime:full -f Dockerfile .
4041
shell: bash
4142
- name: Log in to GHCR
4243
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u skunxicat --password-stdin

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ RUN --mount=type=secret,id=github_token \
2424
FROM public.ecr.aws/lambda/provided:al2023
2525

2626
# Install only runtime dependencies
27-
RUN dnf install -y jq && \
27+
RUN dnf install -y jq python3 python3-libs && \
2828
dnf clean all && \
2929
rm -rf /var/cache/dnf
3030

3131
# Copy AWS CLI binaries only
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+
3539
# Copy http-cli
3640
COPY --from=builder /http-cli-bin/http-cli /var/task/bin/http-cli
3741

build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ set -e
77
PLATFORM="linux/arm64"
88
MODE="--load"
99
TAG="lambda-shell-runtime"
10-
VARIANTS="tiny slim full"
10+
# VARIANTS="tiny slim full"
11+
VARIANTS="tiny micro"
1112

1213

1314
# Parse arguments

micro.Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM public.ecr.aws/lambda/provided:al2023 AS builder
2+
3+
RUN dnf install -y unzip python3-pip findutils && \
4+
dnf clean all
5+
6+
# Download http-cli
7+
RUN --mount=type=secret,id=github_token \
8+
curl -H "Authorization: token $(cat /run/secrets/github_token)" \
9+
-L https://github.com/ql4b/http-cli/archive/refs/heads/develop.zip \
10+
-o http-cli.zip && \
11+
unzip http-cli.zip && \
12+
mkdir -p /http-cli-bin && \
13+
mv http-cli-develop/http-cli /http-cli-bin/ && \
14+
chmod +x /http-cli-bin/http-cli && \
15+
rm -rf http-cli.zip http-cli-develop
16+
17+
RUN pip3 install --no-cache-dir --target /tmp/awscurl awscurl && \
18+
find /tmp/awscurl -type d -name '__pycache__' -exec rm -rf {} + && \
19+
find /tmp/awscurl -type f -name '*.pyc' -delete && \
20+
find /tmp/awscurl -type d -name '*.dist-info' -exec rm -rf {} +
21+
22+
# Stage 2: Runtime stage
23+
FROM public.ecr.aws/lambda/provided:al2023
24+
25+
# Install only runtime dependencies
26+
RUN dnf install -y jq python3 && \
27+
dnf clean all && \
28+
rm -rf /var/cache/dnf
29+
30+
# Copy only what's needed
31+
COPY --from=builder /tmp/awscurl /var/task/aws
32+
# Clean up Python cache and metadata
33+
RUN rm -rf \
34+
/var/task/aws/__pycache__ \
35+
/var/task/aws/*.dist-info \
36+
/var/task/aws/**/__pycache__
37+
38+
ENV PYTHONPATH="/var/task/aws"
39+
40+
RUN mkdir -p /var/task/bin && \
41+
printf '#!/bin/sh\nexport PYTHONPATH=/var/task/aws\nexec python3 -m awscurl.awscurl "$@"\n' > /var/task/bin/awscurl && \
42+
chmod +x /var/task/bin/awscurl
43+
44+
# Copy http-cli
45+
COPY --from=builder /http-cli-bin/http-cli /var/task/bin/http-cli
46+
ENV PATH="/var/task/bin:${PATH}"
47+
48+
COPY runtime/bootstrap /var/runtime/bootstrap
49+
RUN chmod +x /var/runtime/bootstrap
50+
51+
WORKDIR /var/task
52+
53+
COPY functions/handler.sh handler.sh

test/run

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ docker run \
1818
lambda-shell-runtime:debug-tiny \
1919
/var/runtime/bootstrap
2020

21+
docker run \
22+
-p 9000:8080 \
23+
--platform linux/arm64 \
24+
-v ~/.aws:/root/.aws:ro \
25+
--env AWS_PROFILE=${AWS_PROFILE} \
26+
--env AWS_REGION=${AWS_REGION} \
27+
--volume ~/.aws-lambda-rie:/aws-lambda \
28+
--entrypoint /aws-lambda/aws-lambda-rie \
29+
--env HANDLER="handler.hello" \
30+
lambda-shell-runtime:debug-tiny \
31+
/var/runtime/bootstrap
32+
33+
34+
docker run -d --rm \
35+
-p 9000:8080 \
36+
--platform linux/arm64 \
37+
-v ~/.aws:/root/.aws:ro \
38+
--volume ~/.aws-lambda-rie:/aws-lambda \
39+
--entrypoint /aws-lambda/aws-lambda-rie \
40+
--env HANDLER="handler.hello" \
41+
lambda-shell-runtime:micro \
42+
/var/runtime/bootstrap
43+
44+
45+
2146
# Invoke test: basic curl request
2247
curl -XPOST \
2348
"http://localhost:9000/2015-03-31/functions/function/invocations" \

0 commit comments

Comments
 (0)