Deep Dive On Serverless - Application - Development
Deep Dive On Serverless - Application - Development
Development
Danilo Poccia, Technical Evangelist
@danilop
© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Agenda
Changes in
data state Node.js
Python
Requests to Java
endpoints C#
Changes in
resource state
Example event sources that trigger AWS Lambda
DATA STORES ENDPOINTS
Amazon S3 Amazon Amazon Amazon Amazon AWS IoT AWS Step Amazon
DynamoDB Kinesis Cognito API Gateway Functions Alexa
AWS AWS CloudTrail AWS Amazon Amazon Amazon SNS Cron events
CloudFormation CodeCommit CloudWatch SES
AWS Lambda
functions
API Gateway
Cache
Mobile Apps
Endpoints on
Amazon EC2
Internet Amazon
Websites
CloudFront
All publicly
accessible
Services endpoints
</>
• .zip file consisting of • Either .zip file with all • Either .zip file with all
your code and any code/dependencies, code/dependencies,
dependencies or standalone .jar or a standalone .dll
• Use npm/pip to • Use Maven / Eclipse • Use NuGet /
install libraries IDE plugins VisualStudio plugins
• All dependencies • Compiled class & • All assemblies (.dll)
must be at root level resource files at root at root level
level, required jars in
/lib directory
AWS CloudFormation
Create templates of your infrastructure
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://flourish-demo-bucket/todo_list.zip
Handler: index.gethtml
Runtime: nodejs4.3
Policies: AmazonDynamoDBReadOnlyAccess
Events:
GetHtml:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
ListTable:
Type: AWS::Serverless::SimpleTable
AWS commands – Package & Deploy
Package
•Creates a deployment package (.zip file)
•Uploads deployment package to an Amazon S3 bucket
•Adds a CodeUri property with S3 URI
Deploy
•Calls CloudFormation ‘CreateChangeSet’ API
•Calls CloudFormation ‘ExecuteChangeSet’ API
Versioning, Stages, Variables
Function versioning and aliases
• Versions = immutable copies of
code + configuration
• Aliases = mutable pointers to
versions
Lambda Function Lambda Function
Version $LATEST Version 123
client
API Gateway Stages
Using Stage Variables in API Gateway together with Lambda function Aliases
helps you manage a single API configuration and Lambda function for multiple
stages
Works like a source repository – clone your API to create a new version:
API 1
(v1) Stage (dev)
Stage (prod)
API 2
(v2)
Stage (dev)
Continuous Integration &
Continuous Delivery for
Serverless Applications
AWS CodeBuild
Fully managed build service that compiles source code,
runs tests, and produces software packages
environment_variables:
plaintext:
"INPUT_FILE": "saml.yaml”
"S3_BUCKET": "”
phases:
install:
commands:
- npm install
pre_build:
commands:
- eslint *.js
build:
commands:
- npm test
post_build:
commands:
- aws cloudformation package --template $INPUT_FILE --s3-
bucket $S3_BUCKET --output-template post-saml.yaml
artifacts:
type: zip
files:
- post-saml.yaml
- beta.json
buildspec.yml Example
version: 0.1
phases:
• Examples for what you can do in
install: the phases of a build:
commands: • You can install packages or run
- npm install
pre_build:
commands to prepare your
commands: environment in ”install”.
- eslint *.js • Run syntax checking,
build: commands in “pre_build”.
commands:
- npm test • Execute your build
post_build: tool/command in “build”
commands: • Test your app further or ship a
- aws cloudformation package --template $INPUT_FILE --s3- container image to a repository
bucket $S3_BUCKET --output-template post-saml.yaml
artifacts: in post_build
type: zip
files: • Create and store an artifact in S3
- post-saml.yaml
- beta.json
Where to Focus Your Tests:
UI 10%
Service 20%
Unit 70%
What service and release step corresponds with which tests?
UI
Test
Service
Third Party
Tooling
Build
Unit AWS CodeBuild
AWS CodePipeline
Build
CodeBuild StagePipeline
AWS CodeBuild Action
Transition
Deploy
JavaApp
Elastic Beanstalk
AWS CodePipeline
MyApplication
Source
Source
GitHub
Build
CodeBuild NotifyDevelopers
AWS CodeBuild Lambda
Parallel actions
Deploy
JavaApp
Elastic Beanstalk
AWS CodePipeline
MyApplication
Source
Source
GitHub
Build
CodeBuild NotifyDevelopers
AWS CodeBuild Lambda
Sequential actions
TestAPI
Runscope
Deploy
JavaApp
Elastic Beanstalk
AWS CodePipeline
MyApplication
Build
CodeBuild
AWS CodeBuild
Staging-Deploy
JavaApp
Elastic Beanstalk
QATeamReview
Manual Approval
Manual Approvals
Review
Prod-Deploy
JavaApp
Elastic Beanstalk
Deploy via CodePipeline
Pipeline flow:
1. Commit your code to a source code repository
2. Package in CodeBuild
3. Use CloudFormation actions in CodePipeline to
create or update stacks via SAM templates
Optional: Make use of ChangeSets
4. Make use of specific stage/environment
parameter files to pass in Lambda variables
5. Test our application between stages/environments
Optional: Make use of Manual Approvals
AWS CodeStar
New!
Metrics, Monitoring,
Logs, and Profiling
Serverless Applications
Amazon CloudWatch
Lambda Logging
• Logging directly from your code
• Basic request information included
API Gateway Logging
• 2 Levels of logging, ERROR and INFO
• Optionally log method request/body content
• Set globally in stage, or override per method
Log Pivots
• Build metrics based on log filters
• Jump to logs that generated metrics
Custom
CloudWatch
Dashboards
AWS X-Ray
industry data
● Integration layer
Recurring task
• Software provisioning
• Security patches
AZ a AZ b AZ c
Drawbacks
Dev. Experience
• Define triggers
(API Gateway or Schedule)
• Deploy as Lambda
Some lessons learned
• Cost of $8 a month.
• AWS X-Ray
Improve debugging experience
Lambda is a fundamental
component of modern
application architectures