The document provides an extensive overview of AWS Lambda and its serverless computing features, highlighting its advantages like flexible scaling, cost efficiency, and ease of use. It discusses Lambda's functionality, including supported services, languages, execution roles, and error handling. Additionally, it outlines pricing, deployment limits, and the pros and cons of using AWS Lambda for application development.
What is serverlesscomputing?
-SCALE: flexible scale without worrying about
complex and time-consuming data
migrations.
- SIMPLICITY: you don’t manage any servers
and OS.
- AVAILABILITY: managed by cloud provider
- COST: you pay only for the requests served
and the compute time required to run your
code
10
Lambda permissions model
-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
- 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 Lambda function
IAM Role Function (resource) policy
18
19.
Lambda Configuration
- Computeresources
- Maximum execution time (timeout)
- IAM role (execution role)
- Handler name
19
20.
Lambda execution context
EachExecution Context provides
500MB of additional disk space in the
/tmp directory. The directory content
remains when the Execution Context is
frozen, providing transient cache that
can be used for multiple invocations
Any declarations in your Lambda
function code (outside the handler code)
remains initialized, providing additional
optimization when the function is
invoked again (for example Database
connections, Environment Variables)
How? What?
20
21.
Programming model
- Handler.Handler is the function AWS Lambda calls to start execution of your
Lambda function.
- Context. AWS Lambda also passes a context object to the handler function, as
the second parameter. Via this context object your code can interact with AWS
Lambda.
- Logging. Your Lambda function can contain logging statements. AWS Lambda
writes these logs to CloudWatch Logs.
- Exceptions. Your Lambda function needs to communicate the result of the
function execution to AWS Lambda.
21
22.
Lambda Function Handler
-inputType: The first handler parameter is the input to the handler, which can be
event data (published by an event source) or custom input that you provide such
as a string or any custom data object.
- outputType: If you plan to invoke the Lambda function synchronously (using the
RequestResponse invocation type), you can return the output of your function
using any of the supported data types. If you plan to invoke the Lambda function
asynchronously (using the Event invocation type), the outputType should be void.
22
Lambda logging
- AWSLambda recommends Log4j 2 to
provide a custom appender. You can use
the custom Log4j appender provided by
Lambda for logging from your lambda
functions.
- In addition, you can also use the statements
“System.out()” and “System.err()” in your
Lambda function code to generate log
entries.
AWS CloudWatch
Options
24
Limits per invocation
27
Memoryallocation range
Ephemeral disk capacity (*/tmp* space)
Number of file descriptors
Number of processes and threads (combined total)
Max execution duration per request
Invoke request body payload size
(RequestResponse/synchronous invocation)
Invoke request body payload size
Min 128 MB / Max 3008 MB (with 64 MB Increments)
512 MB
1,024
1,024
300 seconds
6 MB
128 KB
Resource Limits
28.
Deployment limits
28
Item DefaultLimit
Lambda function deployment package size (compressed .zip/.jar file) 50 MB
Total size of all the deployment packages that can be uploaded per region 75 MB
Size of code/dependencies that you can zip into a deployment package
(uncompressed .zip/.jar file)
Note
- Each Lambda function receives an additional 500 MB of non-persistent disk
space in it's own /tmp directory. The /tmp directory can be used for loading
additional resources like dependency libraries or data or data sets during
function initialization
250 MB
Total size of environment variables set 4 KB
29.
29
Lambda pricing
1 Mrequests
per month
400,000 GB-SECONDS
of compute time per month
The Lambda free tier does
not automatically expire at
the end of your 12 month
AWS Free Tier term, but is
available to both existing and
new AWS customers
indefinitely.
Free Tier
1 M requests free
First 1M requests per month
are free
$0.20 Per 1M requests
thereafter
$0.0000002 per request
Requests
400,000 GB-SECONDS per
month free
First 400,000 GB-seconds
per month up to 3.2M
seconds of compute time, are
free
$0.00001667 for every GB-
second used thereafter
The price depends on the
amount of memory you
allocate to your function
Duration
29
30.
Lambda pros andcons
- Scaling
- Faster Development
- Operational Management
- Reduction in Operational
- Costs
+
30
31.
Lambda pros andcons
- Scaling
- Faster Development
- Operational Management
- Reduction in Operational
- Costs
- Execution Duration
- Stateless
- Testing
- Monitoring and Debugging
- Denial of Service
- Tracking
+ -
31