8. By Definition
"... code execution model in which the cloud provider fully
manages starting and stopping of a function's container
platform as a service (PaaS) as necessary to serve requests,
and requests are billed by an abstract measure of the
resources required to satisfy the request, rather than per
virtual machine, per hour."
— Wikipedia
10. So, what is Lambda?
AWS offering of Faas launched at re:Invent 2014
Officially supports C#, Java, NodeJS, Python
Pricing based on function execution requests, duration
and assigned memory
11. Runtime Environment
Amazon Linux AMI (RHEL-based w kernel v4.4) container
with function code
Node 4.3.2 & 6.10, Java 8, Python 2.7 & 3.6, .NET Core 1.0.1
AWS SDK library included
Supports KMS encrypted environment variables
Memory from 128 to 1536 MB
12. Default Limits
/tmp space = 512 MB
Max execution time = 300 seconds
Total processes & threads = 1024
Concurrent executions = 1000
Deployment package size = 50 MB
13. Common Code Model
Handler function: entry point & gets event data
Context object: contains runtime info
Code should be stateless
Do or do not; there is no try (return success or failure)
16. Event sources
Event sources are the heart of event-driven apps
Vary on async vs sync invocation
Custom sources supported with Invoke API
S3, Cloudwatch, Kinesis, Dynamo, API Gateway plus
many more
18. Frameworks - Apex
apex.run
Unix philosophy
Project structure w/ multiple envs and functions
Also supports golang, clojure and rust
Integrates with terraform for infra
21. Logging
Add logs to your code!
They get shipped to Cloudwatch:
/aws/lambda/<function_name>
Lambda console, cloudwatch, or x-amz-log-results
response header
22. Monitoring
Look at 3rd party tools
Instrument and/or trace your code - AWS Xray!
Metrics sent to Cloudwatch:
- Invocations
- Errors
- Duration
- Throttles
23. Retries
stream based vs non-stream based
non-stream & synchronous - client should add retry
logic
non-stream & async - auto retry twice with delays then
discarded*
stream - will retry until success or until data expires
24. Networking
To VPC or not to VPC?
All inbound network connections are blocked
Outbound connections are TCP only
26. Security
No vulnerabilities through unpatched servers
DDoS becomes just a billing issue
Immutability eliminates compromised servers
You still own security in your code!
28. Requests Pricing
First 1 million requests per month are free!
20 cents per 1 million requests thereafter
29. Duration Pricing
Code execution time, rounded up to nearest 100 ms
Price is dependent on memory allocation using GB-
seconds formula
You get 400,000 GB-seconds free per month
$0.00001667 per GB-s thereafter
30. Pricing example
Function gets 3m requests per
month and takes 1s per request.
512 mb memory allocation:
3m requests * 1s = 3,000,000
3,000,000 * 512mb / 1024 =
1,500,000 GB-s
1,500,000 - 400,000 (free tier) =
1,100,000 GB-s
1,100,000 * $0.00001667 = $18.74
Total cost: $18.74 month