deep dive on aws lambda

38
Deep Dive on AWS Lambda Heitor Lessa, Solutions Architect, AWS Serverless

Upload: amazon-web-services

Post on 21-Jan-2018

1.129 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Deep Dive on AWS Lambda

Deep Dive on AWS Lambda

Heitor Lessa, Solutions Architect, AWS Serverless

Page 2: Deep Dive on AWS Lambda

About me

Heitor LessaDeveloper TechnologiesAmazon Web Services

• 10 years of sysadmin, networking and• systems architecture background.• AWS User since 2011 then joined AWS in 2013• Go by Bob on Starbucks• Python/Node

Twitter: @heitor_lessaEmail: [email protected]

Page 3: Deep Dive on AWS Lambda

What to expect from today’s webinar

Ø Fundamentals of AWS LambdaØ Authoring functions and AWS Lambda environmentØ ALM for AWS LambdaØ Debugging and operations for AWS LambdaØ Questions & answers

Page 4: Deep Dive on AWS Lambda

What NOT to expect from today’s webinar

Ø Deep dive on CI/CD for Serverless applicationsØ Deep dive on Serverless platform

Ø Amazon API GatewayØ Amazon DynamoDBØ AWS Lambda@EdgeØ AWS Step FunctionsØ AWS X-Ray, etc.

Ø Deep dive on Best Practices

Page 5: Deep Dive on AWS Lambda

Virtual Serversin the Cloud

Physical Serversin Datacenters

Virtual Serversin Datacenters

Containersin the Cloud

Serverless with the Cloud

Evolving to Serverless

Page 6: Deep Dive on AWS Lambda

A serverless world…

No servers to provision or manage

Scales with usage

Never pay for idle Availability and fault tolerance built in

Page 7: Deep Dive on AWS Lambda

Customers

Page 8: Deep Dive on AWS Lambda

Common use cases for Serverless Applications

Web Applications• Static

websites

• Complex web apps

• Packages for Flask and Express

Data Processing• Real time

• MapReduce

• Batch

Chatbots

• Powering chatbot logic

Backends

• Apps & services

• Mobile

• IoT

</></>

Amazon Alexa• Powering

voice-enabled apps

• Alexa Skills Kit

Autonomous IT• Policy engines

• Extending AWS services

• Infrastructure management

Page 9: Deep Dive on AWS Lambda

Fundamentals of AWS Lambda

Page 10: Deep Dive on AWS Lambda

Fine-Grained Pricing

Buy compute time in 100ms increments

Low request charge

No hourly, daily, or monthly minimums

No per-device fees

Never pay for idleFree Tier

1M requests and 400,000 GB-s of compute.Every month, every customer.

Page 11: Deep Dive on AWS Lambda

Working with AWS Lambda

EVENT SOURCE FUNCTION SERVICES (ANYTHING)

Changes in data state

Requests to endpoints

Changes in resource state

NodePythonJavaC#… more coming soon

Page 12: Deep Dive on AWS Lambda

Lambda execution model

Synchronous (push) Asynchronous (event) Stream-based

AmazonAPI Gateway

AWS Lambda function

Amazon DynamoDBAmazon

SNS

/order

AWS Lambda function

Amazon S3

reqs

Amazon Kinesis

changes

AWS Lambda service

function

Page 13: Deep Dive on AWS Lambda

Amazon S3 Amazon DynamoDB

Amazon Kinesis

AWS CloudFormation

AWS CloudTrail

Amazon CloudWatch

Amazon SNSAmazonSES

AmazonAPI Gateway

Amazon Cognito

AmazonAlexa

Cron events

DATA STORES ENDPOINTS

REPOSITORIES EVENT/MESSAGE SERVICES

Event Sources that integrate with AWS Lambda

… and the list will continue to grow!

Amazon RDSAurora

AWS Step Functions

ORCHESTRATION AND STATE MANAGEMENT

AWS IoT

Page 14: Deep Dive on AWS Lambda

Monitoring and debugging Lambda Functions

• AWS Lambda console includes a dashboard for functions

• Lists all Lambda functions• Easy editing of resources, event

sources and other settings• At-a-glance metrics

• Metrics automatically reported to Amazon CloudWatch for each Lambda function

• Requests• Errors• Latency• Throttles

• Logs captured by Amazon CloudWatch Logging service

Page 15: Deep Dive on AWS Lambda

Authoring functions and AWS Lambda environment

Page 16: Deep Dive on AWS Lambda

Anatomy of a Lambda function

Handler() function

Function to be executed upon invocation

Event object

Data sent during Lambda Function Invocation

Context object

Methods available to interact with runtime information (request ID, log group, etc.)

s3 = boto3.resource('s3')app = App()

def lambda_handler(event, context):# do something

...

Page 17: Deep Dive on AWS Lambda

The execution environment – Amazon Linux

Compile native binaries against Lambda AMI

Test using exact version of libraries available

Always package own SDKs/Libraries within functions

docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html

Page 18: Deep Dive on AWS Lambda

ALM for AWS Lambda

Page 19: Deep Dive on AWS Lambda

CI/CD – Code*, Cloudformation and SAM

MonitorProvisionDeployTestBuildCode

CloudWatchCloud

FormationCode

Commit

CodePipeline

CodeBuild

X-Ray

Page 20: Deep Dive on AWS Lambda

Frameworks

Chalice

aws.amazon.com/serverless/developer-tools

Page 21: Deep Dive on AWS Lambda

Local development with SAM Local (Beta)

Test functions locally via Docker containers

Run API Gateway locally with hot-reloading

Validate SAM templates

Support for local debugging

NEW!

awslabs/aws-sam-local

Page 22: Deep Dive on AWS Lambda

Debugging and operations for AWS Lambda

Page 23: Deep Dive on AWS Lambda

X-Ray service

Page 24: Deep Dive on AWS Lambda

X-Ray – Application Insights

Page 25: Deep Dive on AWS Lambda

X-Ray – Application Insights

Page 26: Deep Dive on AWS Lambda

X-Ray – Application Insights

Page 27: Deep Dive on AWS Lambda

Application instrumentation (Node.js)

Page 28: Deep Dive on AWS Lambda

Build an App with AWS CodeStar and receive $50 in AWS Credits

Register using the link below to receive AWS

Credits*

1

Click the tweet icon in the console to share your app on

Twitter

2

Build your app in the AWS CodeStar console

3

* Amazon Web Services (AWS) Promotional Credits will be awarded once per user for a limited time only upon successful completion of the challenge. $50 in AWS Promotional Credits will be awarded via email within 10-12 days of submission and are valid until December 31, 2018. Customers are limited to having two promotional credits on their AWS account at a given time.

Go to https://aws.amazon.com/codestar/codestar-credit-challenge/ for details

Page 29: Deep Dive on AWS Lambda

Thank you!

Page 30: Deep Dive on AWS Lambda

Appendix

Page 31: Deep Dive on AWS Lambda

AWS Lambda limitsResource Limits Default Limit

Ephemeral disk capacity ("/tmp" space) 512 MB

Number of file descriptors 1024

Number of processes and threads (combined total) 1024

Maximum execution duration per request 300 seconds

Invoke request body payload size (RequestResponse) 6 MB

Invoke request body payload size (Event) 128 K

Invoke response body payload size (RequestResponse) 6 MB

Dead-letter payload size (Event) 128 K

Deployment Limits Default Limit

Lambda function deployment package size (.zip/.jar file) 50 MB

Size of code/dependencies that you can zip into a deployment package (uncompressed zip/jar size) 250 MB

Total size of all the deployment packages that can be uploaded per region 75 GB

Total size of environment variables set 4 KB

Throttling Limits (can request service limit increase) Default Limit

Concurrent executions 1000NEW!

Page 32: Deep Dive on AWS Lambda

The push model and resource policies

Function (resource) policy

• Permissions you grant to your Lambda function determine which service or event source can invoke your function

• Resource policies make it easy to grant cross-account permissions to invoke your Lambda function

Page 33: Deep Dive on AWS Lambda

The pull model and IAM roles

IAM (execution) role

• Permissions you grant to this role determine what your AWS Lambda function can do

• If event source is Amazon DynamoDB or Amazon Kinesis, then add read permissions in IAM role

Page 34: Deep Dive on AWS Lambda

Building blocks for serverless applications

AWS Lambda Amazon DynamoDB

Amazon SNS

Amazon API GatewayAmazon SQS

Amazon Kinesis

Amazon S3

Orchestration and State Management

API Proxy Messaging and Queues Analytics

Monitoring and Debugging

Compute Storage Database

AWS X-RayAWS Step Functions

Page 35: Deep Dive on AWS Lambda

Testing strategies

Run Unit tests locally

Run Integration/Acceptance tests with real services

Leverage Lambda Runtime AMI

Page 36: Deep Dive on AWS Lambda

Separate business logic from function signature

app = Todo()

def lambda_handler(event, context):ret = app.dispatch(event)

return {'statusCode': ret["status_code"],'headers': ret["headers"],'body': json.dumps(ret["body"])

}

Page 37: Deep Dive on AWS Lambda

Cloudwatch – Metrics and streaming

Leverage built-in metrics and alarm on aggregated (throttling )

Create Custom Metrics via Metric Filter out of logs

Stream and centralize logs from multiple accounts to Amazon ElasticSearch for near real-time analysis

Use X-Ray to drill down application insights

built-in custom

Amazon Cloudwatch

Page 38: Deep Dive on AWS Lambda

Compute power: Don’t “guesstimate”

alexcasalboniaws-lambda-power-tuning