Iam trying to build a lambda docker image for a golang function, after reading through the docs on AWS I copied the example dockerfile provided using the recommended base image of lambda/provided:al2
Changed the first base image that provides the golang runtime to match local golang runtime of 1.19.
Dockerfile:
FROM golang:1.19 as build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main
FROM public.ecr.aws/lambda/provided:al2
COPY --from=build /app/main ./main
ENTRYPOINT [ "./main" ]
After a successful build I run this command (from aws docs):
docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 --entrypoint /aws-lambda/aws-lambda-rie go-test-image:latest ./main
Which returns the error: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/aws-lambda/aws-lambda-rie": stat /aws-lambda/aws-lambda-rie: no such file or directory: unknown.
but reading the docs the AWS provided image already includes the aws-lambda-rie
I have also tried to run:
docker run -p 9000:8080 go-test-image:latest
which returns errors of missing lambda environment variables:
expected AWS Lambda environment variables [_LAMBDA_SERVER_PORT AWS_LAMBDA_RUNTIME_API]
Any ideas of what I am missing on this, or cause of these errors.
but reading the docs the AWS provided image already includes the aws-lambda-rie
It is included, but seems to be referenced incorrectly in the docs.
Digging around inside the image, there is /lambda-entrypoint.sh which references /usr/local/bin/aws-lambda-rie.
You can use that directly as the docs suggest.
Edit: The below does not work. /lambda-entrypoint.sh references /var/runtime/bootstrap, which I expect is only included in AWS base images for specific languages. As we're using Go, the compiled executable is the runtime.
, or instead, make use of /lambda-entrypoint.sh as your entrypoint:
ENTRYPOINT [ "/lambda-entrypoint.sh", "./main" ]
/lambda-entrypoint.sh detects when your container is running locally and makes use of the RIE. If your container is running in the cloud, it executes the Lambda runtime bootstrap script directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With