AWS Lambda:
Features and Uses
Dmytro Harbuzov
Senior Software Engineer, Сonsultant
Agenda
1. Introduction
2. Amazon Web Services overview
3. AWS Lambda serverless computing
4. AWS Lambda pros and cons
2
Cloud computing
3
Applications
Security
Databases
Operating Systems
Virtualization
Servers
Storage
Networking
Data Centers
Enterprise IT Infrastructure Platform Software
Customer
Customer
Provider
Customer
Provider Provider
4
Amazon Web Services
Overview
5
AWS product’s categories
6
Global Infrastructure
7
Global Infrastructure
8
AWS Lambda & serverless
computing
9
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
11
Supported services
Amazon data stores
S3
Dynamo DB
Kinesis
Cognito
AWS:
- CloudFormation
- CloudTrail
- CodeCommit
Amazon CodeCommit
Amazon Alexa
Amazon API Gateway
AWS lo T
Amazon SES
Amazon SNS
Cron events
Repositories
End points
Event/message services
12
Supported languages
13
14
Serverless applications
Event Source Function Services
14
15
Example synchronous model
15
15
Custom App AWS Lambda Execution Role
Lambda
Function
16
16
Example asynchronous model
User AWS LambdaExecution Role
Lambda
Function
Amazon S3
Access
Policy
Source Bucket
Notification
Configuration
17
Example stream-based model
17
Custom App AWS LambdaExecution Role
Lambda
Function
Amazon Kinesis
Event Source
Mapping
Stream
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
Lambda Configuration
- Compute resources
- Maximum execution time (timeout)
- IAM role (execution role)
- Handler name
19
Lambda execution context
Each Execution 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
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
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 Context Object
- getMemoryLimitInMB()
- getFunctionName()
- getFunctionVersion()
- getInvokedFunctionArn()
- getAwsRequestId()
- getLogStreamName()
- getLogGroupName()
- getClientContext()
- getIdentity()
- getRemainingTimeInMillis()
- getLogger()
23
Lambda logging
- AWS Lambda 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
Lambda error handling
25
Lambda error handling with AWS
Step Functions
Function
Example
START CATCH
26
26
END
Limits per invocation
27
Memory allocation 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
Deployment limits
28
Item Default Limit
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
Lambda pricing
1 M requests
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
Lambda pros and cons
- Scaling
- Faster Development
- Operational Management
- Reduction in Operational
- Costs
+
30
Lambda pros and cons
- Scaling
- Faster Development
- Operational Management
- Reduction in Operational
- Costs
- Execution Duration
- Stateless
- Testing
- Monitoring and Debugging
- Denial of Service
- Tracking
+ -
31
Thank you!
dmytro.harbuzov@gmail.com

AWS Lambda Features and Uses

  • 1.
    AWS Lambda: Features andUses Dmytro Harbuzov Senior Software Engineer, Сonsultant
  • 2.
    Agenda 1. Introduction 2. AmazonWeb Services overview 3. AWS Lambda serverless computing 4. AWS Lambda pros and cons 2
  • 3.
  • 4.
    Applications Security Databases Operating Systems Virtualization Servers Storage Networking Data Centers EnterpriseIT Infrastructure Platform Software Customer Customer Provider Customer Provider Provider 4
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
    AWS Lambda &serverless computing 9
  • 10.
    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
  • 11.
  • 12.
    Supported services Amazon datastores S3 Dynamo DB Kinesis Cognito AWS: - CloudFormation - CloudTrail - CodeCommit Amazon CodeCommit Amazon Alexa Amazon API Gateway AWS lo T Amazon SES Amazon SNS Cron events Repositories End points Event/message services 12
  • 13.
  • 14.
  • 15.
    15 Example synchronous model 15 15 CustomApp AWS Lambda Execution Role Lambda Function
  • 16.
    16 16 Example asynchronous model UserAWS LambdaExecution Role Lambda Function Amazon S3 Access Policy Source Bucket Notification Configuration
  • 17.
    17 Example stream-based model 17 CustomApp AWS LambdaExecution Role Lambda Function Amazon Kinesis Event Source Mapping Stream
  • 18.
    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
  • 23.
    Lambda Context Object -getMemoryLimitInMB() - getFunctionName() - getFunctionVersion() - getInvokedFunctionArn() - getAwsRequestId() - getLogStreamName() - getLogGroupName() - getClientContext() - getIdentity() - getRemainingTimeInMillis() - getLogger() 23
  • 24.
    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
  • 25.
  • 26.
    Lambda error handlingwith AWS Step Functions Function Example START CATCH 26 26 END
  • 27.
    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
  • 32.