2. Agenda
1. AWS Serverless concepts
2. Serverless in the framework of business
3. AWS Serverless architectural approaches
4. AWS Lambdas overview and deployment models
5. Infrastructure as Code in AWS Serverless
6. CI/CD for AWS Serverless applications
7. AWS Serverless practical aspects
8. AWS Lambda monitoring and pitfalls
3. About me
Education:
Kharkiv National University of radio-electronics
Work experience:
3 years of software development expertise (full stack)
1 year of expertise in data engineering
Hobbies:
Cookery, cycling, skiing, painting
10. Business benefits
Shorter time to
market
Increased
efficiency
Fixed costs
become variable
costs
Less waste More flexibility
Better service
stability
Better
management of
development
and testing
11. Serverless use cases
Web apps and back-end API Data processing and analytics
Internet of thingsChat bots
Third-party integrations
Internal tooling
20. AWS Lambda
Concept to run the code
without provisioning or
managing servers
Virtually supporting any
type of application or back-
end service – with zero
administration
Resource allocation on
demand which ensures cost-
effectiveness
21. Lambda function anatomy
Handler function
function to be executed
upon invocation
Event object
data sent during
function invocation
Context object
contains runtime
information
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class LambdaFunction implements RequestHandler<Object, Object> {
@Override
public Object handleRequest(Object obj, Context context) {
// TODO implement
context.getLogger().log("Hello Lambda Function!");
return null;
}
}
24. AWS Serverless Application Model
Open-source framework for
building serverless applications
Simple and clean syntax
Lambda-like execution env for
local development
Applications are defined by SAM
templates (yaml)
Transforms SAM templates into
AWS CloudFormation syntax
25. AWS CloudFormation
Service to model and set up AWS
resources
Simplify infrastructure management
Quick replication of infrastructure
Easily control and track changes to
infrastructure
Templates in json or yaml transform
into stacks
Changes in stacks are tracked by
change sets
26. Lambda with AWS SAM
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description : Sample SAM Template for sam-app
Globals:
Function:
Timeout: 20
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
Handler: helloworld.LambdaFunction::handleRequest
Runtime: java8
Environment:
Variables:
PARAM1: VALUE
sam build && sam local invoke --event event.json
sam deploy --guided
28. Serverless Application Model vs CloudFormation
SAM CloudFormation
Template format Yaml Yaml and json
Concept Framework as
CloudFormation extension
Service to manage
resources
Deployment Template is transformed
into CloudFormation one
and deployed into stack
Stack is the result of
template deployment
Function definition Function is defined by
AWS::Serverless::Function
Function is defined by
AWS::Lambda::Function
Local development Provides local lambda-like
environment
Doesn’t provide local
development features
API SAM API AWS SDK API for
CloudFormation
Supported resources Limited list of supported
resources
Extended list of supported
resources
Purpose Serverless applications Complete infrastructure
30. Infrastructure as Code
Provisioning and managing
cloud resources by writing a
template file that is both
human readable, and machine
consumable
For AWS cloud
development the built-in
choice for infrastructure
as code is AWS
CloudFormation
34. CI/CD in Serverless Applications
AWS CodeCommit
source control service
AWS CodeBuild
continuous integration service
AWS CodeDeploy
deployment service
35. AWS CodePipeline
Release pipelines for fast and reliable application and infrastructure updates
Automates the build, test, and deploy phases
Rapid and reliable features and updates delivery
Integration with third-party services such as GitHub or with the custom plugins
41. Lambda deployment unified approach
LAMBDA_HANDLER_VENDOR=$(LAMBDA_HANDLER_BATCH_$(VENDOR))
# Deploy Lambda template to AWS
aws cloudformation deploy --no-fail-on-empty-changeset
--stack-name $(STACK_LAMBDA_BATCH_METRICS_VENDOR)
--template-file ./lambda-
app/target/classes/$(TEMPLATE_LAMBDA_BATCH_METRICS)
--parameter-overrides "Environment=$(ENV_KEY)"
"DataSourceSuffix=$(SUFFIX_DATA_SOURCE_VENDOR)"
"LambdaHandler=$(LAMBDA_HANDLER_VENDOR)"
"LambdaFunctionName=$(FUNCTION_VENDOR)"
"LambdaScheduleExpression=rate(1 hour)"
--capabilities CAPABILITY_NAMED_IAM
Parameters are defined in separate Makefiles configured
for each vendor separately.
Vendor key is passed as parameter to command.
43. Serverless web application with API Gateway
Amazon S3
API Gateway AWS Lambda
Amazon
CloudFront
Amazon S3 stores all
the static content
API Gateway handles all
the application routing
Lambda runs all the
back-end logic
CloudFront acts as CDN and
is typically used to front this
44. Serverless web application with API Gateway
AWS Data Pipeline AWS Lambda
Amazon S3 acts as
a storage for new
coming data
AWS Data Pipeline
ingests new data by
scheduled interval
Lambda performs final
processing on the data
Third-party data
providers
Third-party data
providers push data to
the respective bucket
Amazon S3
CloudWatch events
(time-based)
Amazon Redshift
Final data storage
Grafana
(visualization)
48. Lambda cold start
What is a cold start?
When running a serverless function, it will stay active (hot) as long as
you're running it
After a period of inactivity, your cloud provider will drop the
container, and your function will become inactive (cold)
A cold start happens when you execute an inactive function. The
delay comes from your cloud provider provisioning your selected
runtime container and then running your function
This process will considerably increase your execution time
!!! Provisioning of the function's container can take > 5 seconds.
That makes it impossible to guarantee < 1 second latency.
49. Lambda warm-up
How to keep Lambda warm?
Create scheduled event to invoke Lambda in configured time interval
to keep the force the container to stay alive
In case of Serverless Framework there’s serverless-plugin-warmup
which provides a possibility to keep Lambda warm
!!! Containers are not reused after ~ 15 minutes of inactivity.
Knowing the system features will help to answer the question
whether the warmup is needed.
50. Lambda pitfalls
Lambda function not invoked by service:
Lambda permissions must be configured to allow invocations
by certain service
Function fails by timeout or memory lack:
Timeout and MemorySize settings should be explicitly stated.
In most cases it’s better to increase Memory Size
Exception occurs during the call inside the function:
In case Lambda performs access to a service, there should be
related permissions configured in Lambda role
Logs don’t appear in CloudWatch:
Function needs permissions to call CloudWatch Logs.
Execution role has to be updated to grant the latter
51. Summary
Serverless approach allows to pay for usage and save the money
Fits to suitable business cases where no dedicated servers are required
Serverless is suitable in case service can be encapsulated in single function
No provisioning and maintenance from your side
Easy local development and testing
Wide range of AWS tools to build Serverless applications