Slide 1

Slide 1 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! © 2021, Amazon Web Services, Inc. or its affiliates. Using container images with serverless functions... and containers! Danilo Poccia Chief Evangelist (EMEA) Amazon Web Services @danilop

Slide 2

Slide 2 text

© 2021, Amazon Web Services, Inc. or its affiliates. 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 2

Slide 3

Slide 3 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! © 2021, Amazon Web Services, Inc. or its affiliates. Using container images to package serverless functions 3

Slide 4

Slide 4 text

© 2021, Amazon Web Services, Inc. or its affiliates. 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. 4

Slide 5

Slide 5 text

© 2021, Amazon Web Services, Inc. or its affiliates. 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

Slide 6

Slide 6 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Container images for AWS Lambda 6 Runtime Interface Client (RIC) Runtime Interface Emulator (RIE) Your code AWS Lambda Local tests

Slide 7

Slide 7 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Test container images locally (using RIC) 7 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

Slide 8

Slide 8 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Base container images – gallery.ecr.aws/lambda 8

Slide 9

Slide 9 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! AWS Lambda functions powered by Arm/Graviton2 9 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/

Slide 10

Slide 10 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! © 2021, Amazon Web Services, Inc. or its affiliates. Tools to help you use container images with serverless functions 10

Slide 11

Slide 11 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! AWS Serverless Application Model (SAM) 11 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

Slide 12

Slide 12 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! AWS Cloud Development Kit (CDK) 12 https://github.com/aws-samples/aws-cdk-lambda-container

Slide 13

Slide 13 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Serverless Framework 13 https://www.serverless.com/blog/container-support-for-lambda

Slide 14

Slide 14 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! © 2021, Amazon Web Services, Inc. or its affiliates. Using the same container images with serverless functions and containers 14

Slide 15

Slide 15 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Same code 15 Container Image #1 Your Code Lambda Function API Gateway Endpoint Container User User Build Container Image #2 Application Load Balancer

Slide 16

Slide 16 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Same container image 16 Container Image Your Code Lambda Function API Gateway Endpoint Container User User Build Application Load Balancer

Slide 17

Slide 17 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Node.js – Serverless Express 17 https://github.com/vendia/serverless-express AWS Lambda + Amazon API Gateway Express Koa Hapi Sails …

Slide 18

Slide 18 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Python – Zappa 18 https://github.com/zappa/zappa AWS Lambda + Amazon API Gateway Django Flask WSGI …

Slide 19

Slide 19 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Java – Serverless Java container 19 https://github.com/awslabs/ aws-serverless-java-container AWS Lambda + Amazon API Gateway Spring Spring Boot Apache Struts Jersey Spark …

Slide 20

Slide 20 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! © 2021, Amazon Web Services, Inc. or its affiliates. Demo “As you like it” 20

Slide 21

Slide 21 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Demo “As you like it” – Here’s the code 21 https://github.com/danilop/serverless-functions-and-containers

Slide 22

Slide 22 text

© 2021, Amazon Web Services, Inc. or its affiliates. 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. 22

Slide 23

Slide 23 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Q&A Let me know what you think J @danilop 23

Slide 24

Slide 24 text

© 2021, Amazon Web Services, Inc. or its affiliates. USING CONTAINER IMAGES WITH SERVERLESS FUNCTIONS... AND CONTAINERS! Thank you! © 2021, Amazon Web Services, Inc. or its affiliates. 24 @danilop