Do you want to run your code without the cost and effort of provisioning and managing servers? Find out how in this deep dive session on AWS Lambda, which allows you to run code for virtually any type of application or back end service – all with zero administration. During the session, we’ll look at a number of key AWS Lambda features and benefits, including automated application scaling with high availability; pay-as-you-consume billing; and the ability to automatically trigger your code from other AWS services or from any web or mobile app.
1. Deep Dive on AWS
Lambda
Heitor Lessa, Solutions Architect,
AWS Serverless
2. About me
Heitor Lessa
Developer Technologies
Amazon 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_lessa
Email: lessa@amazon.com
3. 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
4. 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
5. Virtual Servers
in the Cloud
Physical Servers
in Datacenters
Virtual Servers
in Datacenters
Containers
in the Cloud
Serverless with
the Cloud
Evolving to Serverless
6. A serverless world…
No servers to provision
or manage
Scales with usage
Never pay for idle Availability and fault
tolerance built in
10. 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 idle
Free Tier
1M requests and 400,000 GB-s of compute.
Every month, every customer.
11. Working with AWS Lambda
EVENT SOURCE FUNCTION SERVICES (ANYTHING)
Changes in
data state
Requests to
endpoints
Changes in
resource state
Node
Python
Java
C#
… more coming soon
12. Lambda execution model
Synchronous (push) Asynchronous (event) Stream-based
Amazon
API Gateway
AWS Lambda
function
Amazon
DynamoDBAmazon
SNS
/order
AWS Lambda
function
Amazon
S3
reqs
Amazon
Kinesis
changes
AWS Lambda
service
function
14. 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
16. 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
...
17. 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
21. 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
28. 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
31. AWS Lambda limits
Resource 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 1000
NEW!
32. 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
33. 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
34. Building blocks for serverless applications
AWS Lambda Amazon DynamoDB
Amazon SNS
Amazon API Gateway
Amazon 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
35. Testing strategies
Run Unit tests locally
Run Integration/Acceptance tests with real services
Leverage Lambda Runtime AMI
36. 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"])
}
37. 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