Skip to content

Instantly share code, notes, and snippets.

@embano1
Created September 23, 2022 09:29
Show Gist options
  • Save embano1/7127b0e870696b4fd278bb7a7c18992d to your computer and use it in GitHub Desktop.
Save embano1/7127b0e870696b4fd278bb7a7c18992d to your computer and use it in GitHub Desktop.
Build and run AWS Lambda Containers locally with Go and ko on M1 Mac

download Lambda RUI for M1

mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie \
https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie-arm64 \
&& chmod +x ~/.aws-lambda-rie/aws-lambda-rie

login

aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <ecr_registry>
Login Succeeded

build, make sure ko can push via your aws auth

# create .ko.yaml with this content
defaultBaseImage: public.ecr.aws/lambda/provided:al2.2022.09.22.12
export KO_DOCKER_REPO=<ecr_repo>
ko publish --bare --sbom none --tags ko --platform=linux/arm64 .

run via Docker

docker run -v ~/.aws-lambda-rie:/aws-lambda -p 8080:8080 \
  --entrypoint /aws-lambda/aws-lambda-rie <repo/image:tag> /ko-app/<ko_binary_name>

test

curl -i -d '{"hello":"world"}' localhost:8080/2015-03-31/functions/function/invocations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment