USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Using container images with serverless functions... and containers! Amazon Web Services USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Agenda • Why & how using container images for serverless functions • A quick look at the tools • Using the same container images with serverless functions and traditional container environments USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Using container images to package serverless functions USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Why use container images with serverless functions? Simplify dependency management, especially for dependencies installed outside of the runtime platform (such as OS dependencies). AWS Lambda max deployment package size: • ZIP format: 250 MB • Container image: 10 GB Use existing container tooling. Centralize development workflow around tools processing container images. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! FROM public.ecr.aws/lambda/nodejs:latest COPY app.js package*.json ./ RUN npm install CMD [ "app.lambdaHandler" ] https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/ Base container images prepared by AWS are shared via Docker Hub and Amazon Elastic Container Registry (ECR) Public Command can be overwritten in the function configuration Dockerfile USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Container images for AWS Lambda Runtime Interface Client (RIC) Runtime Interface Emulator (RIE) Your code AWS Lambda Local tests USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Test container images locally (using RIC) docker run \ --env DYNAMODB_TABLE=Movies \ --env AWS_ACCESS_KEY_ID="$(aws configure get default.aws_access_key_id)" \ --env AWS_SECRET_ACCESS_KEY="$(aws configure get default.aws_secret_access_key)" \ --env AWS_SESSION_TOKEN="$(aws configure get default.aws_session_token)" \ --env AWS_REGION="$(aws configure get default.region)" \ -p 9080:8080 \ movie-service list.list curl -s "http://localhost:9080/2015-03-31/functions/function/invocations" -d '{}' | jq USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Base container images – gallery.ecr.aws/lambda USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! AWS Lambda functions powered by Arm/Graviton2 https://aws.amazon.com/blogs/aws/aws-lambda-functions-powered-by-aws-graviton2-processor-run-your-functions-on-arm-and-get-up-to-34-better-price-performance/ USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Tools to help you use container images with serverless functions USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! AWS Serverless Application Model (SAM) https://aws.amazon.com/blogs/compute/using-container-image-support-for-aws-lambda-with-aws-sam Resources: HelloWorldFunction: Type: AWS::Serverless::Function Properties: PackageType: Image ImageConfig: Command: ["app.lambda_handler"] Metadata: Dockerfile: Dockerfile DockerContext: ./hello_world DockerTag: v1 USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! AWS Cloud Development Kit (CDK) https://github.com/aws-samples/aws-cdk-lambda-container USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Serverless Framework https://www.serverless.com/blog/container-support-for-lambda USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Using the same container images with serverless functions and containers USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Same code Container Image #1 Your Code Lambda Function API Gateway Endpoint Container User User Build Container Image #2 Application Load Balancer USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Same container image Container Image Your Code Lambda Function API Gateway Endpoint Container User User Build Application Load Balancer USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Demo “As you like it” USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Takeaways • Using container images to package serverless functions can help if you are already suing containers (and container tooling) in your development workflow. • Container images can simplify managing large dependencies and dependencies managed outside of the runtime. • You can use the same container images to server web traffic with serverless functions and traditional container environments. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Q&A Let me know what you think J USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Thank you!