Supercharge Your Product Development with Continuous Delivery & Serverless Computing: AWS Developer Workshop - Web Summit 2018
Continuous Integration (CI) and Continuous Delivery (CD) help developers automate the software release process. The faster you can release new features and fix bugs, the quicker you can innovate and respond to customer needs. Serverless computing has changed the game for application development, including how to properly perform CI/CD for your application. AWS provides developer tools that help you automate the end-to-end lifecycle of your serverless application. In this session, we will discuss a method for automating the deployment of serverless applications running on AWS Lambda, using services such as AWS CodePipeline and AWS CodeBuild, and techniques such as canary deployments and automatic rollbacks.
Speaker: Alex Casalboni - Technical Evangelist, AWS
Supercharge Your Product Development with Continuous Delivery & Serverless Computing: AWS Developer Workshop - Web Summit 2018
1. Alex Casalboni
Technical Evangelist, AWS
@alex_casalboni
@ 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved
Supercharge Product Development with
Continuous Delivery & Serverless Computing
2. About me
• Software Engineer & Web Developer
• Startupper for 4.5 years
• Serverless Lover & AI Enthusiast
• ServerlessDays Organizer
• AWS Customer since 2013
3. Agenda
1. What is serverless computing
2. Serverless patterns on Amazon Web Services
3. Continuous Delivery & Safe Deployments
4. Demo time
5. Serverless Computing in a nutshell
No servers to provision
or manage
Scales with usage
Never pay for idle Built-in availability and
fault tolerance
6. Event-driven architectures
Services (anything)
Changes in
data state
Requests to
endpoints
Changes in
resource state
Event source Serverless Function
Node.js (6.10, 8.10)
Python (2.7, 3.6)
Java (8)
Go (1.x)
.NET core (1.0, 2.0, 2.1)
C#, F#, PowerShell
7. Common Use Cases
Web apps
• Static
websites
• Complex web
apps
• Packages for
Flask and
Express
Data processing
• Real time
• MapReduce
• Batch
• Machine learning
inference
Chatbots
• Powering
chatbot logic
Backends
• Apps and
services
• Mobile
• IoT
</></>
Amazon Alexa
• Powering
voice-enabled
apps
• Alexa
Skills Kit
IT automation
• Policy engines
• Extending AWS
services
• Infrastructure
management
10. Serverless Functions 101
Simple resource model
• Select RAM/Power (from
128 MB to 3 GB)
• CPU and network
allocated proportionately
Flexible use
• Synchronous or
asynchronous
• Integrated with other
Cloud services
Flexible authorization
• Securely grant access to
Cloud resources
• Fine-grained control for
each function
Bring your own code
• Multiple runtimes
• Bring your own libraries
(even native ones)
11. Serverless Functions 101
Authoring functions
• WYSIWYG editor or
upload packaged .zip
• Cloud-native IDE (Cloud9)
• Third-party plugins
(Eclipse, VS, etc.)
Monitoring and logging
• Metrics for requests,
errors, and throttles
• Built-in logs to the Cloud
• Distributed tracing
(microservices map)
Programming model
• Use processes, threads,
/tmp, sockets normally
• SDK to interact with
other Cloud services
Stateless
• Persist data using
external storage
• No affinity or access to
underlying infrastructure
12. Object
storage
NoSQL
Database
Real-time
data ingestion
IaC provisioning
& automation
Auditing &
Compliance
Platform
Events
User
Authentication
Pub/Sub
Topics
Email hooks
(in/out-bound)
Crojobs
(scheduled)
Data stores Endpoints
Configuration repositories Event/message services
Event Sources
Source Control
(Git)
HTTP interface
(RESTful)
Chatbots and
voice-apps
MQTT
interface
Functions
orchestration
Message
Queues
14. Function Execution Model
Synchronous (push) Asynchronous (event) Stream-based
HTTP request
Function
DB insert/update/deleteNew Message (queue, topic)
File Upload or Update
reqs
changes
Aggregation / buffer
Function
/order
Real-time data ingestion
New User Signup
Function
15. AWS Lambda Execution Model
Synchronous (push) Asynchronous (event) Stream-based
Amazon
API Gateway
AWS Lambda
function
Amazon
DynamoDBAmazon
SNS
AWS Lambda
function
Amazon
S3
reqs changes
AWS Lambda
service
function
/order
Amazon
Kinesis
16. Amazon API Gateway
Unified API
frontend
Authenticate and
authorize requests
DDoS protection
and throttling
Throttle, meter,
and monetize APIs
17. Mobile Apps
Websites
Services
Amazon API Gateway
API Gateway
Cache
Public
Endpoints on
Amazon EC2
Amazon
CloudWatch
Monitoring
All publicly
accessible
endpoints
Lambda
Functions
Endpoints
in VPC
Applications
& Services
in VPC
Any other
AWS service
Fully-managed
CloudFront
Distribution
Edge-OptimizedRegionalPrivate
Customer-managed
CloudFront
Distribution
Applications
& Services
in the same
AWS Region
AWS Direct
Connect
On-premises
Amazon API Gateway Integrations
29. A typical CI/CD pipeline
Source Build Test Production
Continuous integration
Continuous delivery
Continuous deployment
30. Cloud-native CI/CD on AWS
Source Build Test Production
AWS
CodeCommit
AWS
CodeDeploy
AWS
CodeBuild
Third-party
tooling
AWS
CodePipeline
New
31. Custom pipelines with AWS Step Functions
github.com/aws-samples/aws-codepipeline-stepfunctions
32. AWS Serverless Application Model (SAM)
Simplified template-driven deployment model
for serverless applications
New serverless resource types
An extension (Macro) of AWS CloudFormation
Open specification (Apache 2.0)
github.com/awslabs/serverless-application-model
34. SAM Template
Tells AWS CloudFormation this is a
SAM template it needs to transform
Creates a Lambda function with the
referenced managed IAM policy,
runtime, code at the referenced zip
location, and handler as defined.
Also creates an API Gateway and
takes care of all mapping and
permissions necessary
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.gethtml
Runtime: nodejs4.3
Policies: AmazonDynamoDBReadOnlyAccess
Events:
GetHtml:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
35. SAM Template Properties
Handler: index.js
Runtime: nodejs4.3
CodeUri: 's3://my-bucket/my-function.zip'
Description: Creates thumbnails
MemorySize: 1024
Timeout: 15
Policies: AmazonS3FullAccess
Environment:
Variables:
TABLE_NAME: my-table
Events:
PhotoUpload:
Type: S3
Properties:
Bucket: my-photo-bucket
Tracing: Active|PassThrough
From SAM version 2016-10-31
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
36. SAM Template Properties
StageName: prod
DefinitionUri: swagger.yml
CacheClusterEnabled: true
CacheClusterSize: 28.4
Variables:
VarName: VarValue
From SAM version 2016-10-31
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
37. SAM Template Properties
PrimaryKey:
Name: id
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
From SAM version 2016-10-31
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
38. github.com/awslabs/aws-sam-cli
AWS SAM CLI
CLI tool for local testing of serverless apps
Works with Lambda functions and “proxy-style” APIs
Response object and function logs available on your
local machine
Uses open-source Docker-Lambda images to mimic
Lambda’s execution environment (timeout, memory
limits, runtimes)
40. IaC best practices
Smart monitoring & metrics
Data-driven strategies
Customizable hooks
Automatic rollback on Error
What do we need?
41. Fully managed build service that compiles source code,
runs tests, and produces software packages
Scales continuously and processes multiple builds
concurrently
You can provide custom build environments suited to
your needs via Docker images
Pay by the minute for the compute resources you use
Can be used as a “Test” action in CodePipeline
AWS CodeBuild
42. version: 0.1
environment_variables:
plaintext:
"INPUT_FILE": "sam.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-sam.yaml
artifacts:
type: zip
files:
- post-sam.yaml
Variables to be used by phases of
build
Examples for what you can do in the
phases of a build:
• Install packages or run commands to
prepare your environment in ”install”
• Run syntax checking, commands in
“pre_build”
• Execute your build tool in “build”
• Test your app further or ship a
container image to a repository in
post_build
Create and store an artifact in S3
buildspec.yml Example
43. AWS CodeDeploy + AWS Lambda
Deployment Preference Type
Canary10Percent30Minutes
Canary10Percent5Minutes
Canary10Percent10Minutes
Canary10Percent15Minutes
Linear10PercentEvery10Minutes
Linear10PercentEvery1Minute
Linear10PercentEvery2Minutes
Linear10PercentEvery3Minutes
AllAtOnce
• Lambda Alias Traffic Shifting enables canaries
and blue|green deployments
• Automatic rollback based on CloudWatch
Metrics/Alarms
• Pre/Post-Traffic Triggers can integrate with
other services (or even call Lambda functions)
49. Did We Scan Your Badge?
Remember to opt-in to AWS
communications and you will receive a
post-event email with a link to:
• AWS Developer Workshop Slides
• $200 in AWS Credits