deep dive on aws lambda
TRANSCRIPT
Deep Dive on AWS Lambda
Heitor Lessa, Solutions Architect, AWS Serverless
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]
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
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
Virtual Serversin the Cloud
Physical Serversin Datacenters
Virtual Serversin Datacenters
Containersin the Cloud
Serverless with the Cloud
Evolving to Serverless
A serverless world…
No servers to provision or manage
Scales with usage
Never pay for idle Availability and fault tolerance built in
Customers
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
Fundamentals of 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.
Working with AWS Lambda
EVENT SOURCE FUNCTION SERVICES (ANYTHING)
Changes in data state
Requests to endpoints
Changes in resource state
NodePythonJavaC#… more coming soon
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
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
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
Authoring functions and AWS Lambda environment
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
...
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
ALM for AWS Lambda
CI/CD – Code*, Cloudformation and SAM
MonitorProvisionDeployTestBuildCode
CloudWatchCloud
FormationCode
Commit
CodePipeline
CodeBuild
X-Ray
Frameworks
Chalice
aws.amazon.com/serverless/developer-tools
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
Debugging and operations for AWS Lambda
X-Ray service
X-Ray – Application Insights
X-Ray – Application Insights
X-Ray – Application Insights
Application instrumentation (Node.js)
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
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
Thank you!
Appendix
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!
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
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
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
Testing strategies
Run Unit tests locally
Run Integration/Acceptance tests with real services
Leverage Lambda Runtime AMI
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"])
}
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
Compute power: Don’t “guesstimate”
alexcasalboniaws-lambda-power-tuning