/docker-on-lambda

AWS Lambda with docker containers!

Primary LanguageGo

Golang Docker

docker-on-lambda

This repository contains the project files of this video. Read this article for a more in depth text-based tutorial.

commands

Golang

go mod init lambda-function
go mod tidy

ECR

optionally you can create the container repository via the AWS Console

aws ecr create-repository --repository-name lambda-function

Base docker image building and pushing

docker build -t lambda-function:latest .

aws ecr get-login-password --region {region} | docker login --username AWS --password-stdin {account-number}.dkr.ecr.{region}.amazonaws.com

docker tag lambda-function:latest {account-number}.dkr.ecr.{region}.amazonaws.com/lambda-function:latest

docker push {account-number}.dkr.ecr.{region}.amazonaws.com/lambda-function:latest

RIE (Runtime Interface Emulator)

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 \
&& chmod +x ~/.aws-lambda-rie/aws-lambda-rie

docker run -d -v ~/.aws-lambda-rie:/aws-lambda --entrypoint /aws-lambda/aws-lambda-rie  -p 9000:8080 lambda-function:latest /main

curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'