SlideShare a Scribd company logo
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Zürich, AWSomeDay
12. September 2018
How to go serverless with AWS Lambda
Roman Plessl, nine (AWS Partner)
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
About myself and nine
Roman Plessl Working for nine as a Solution
Architect, Consultant and Leader.
As a Cloud Navigator we offer you
AWS Consulting, Migrations and
also Operations.
Besides nine I work as Consultant
and Teacher (ETH, Foundation's)
2
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Motivation for AWS Lambda
With AWS Lambda you don’t need to worry about
provisioning servers or scaling them.
Learn which workloads work best and how to go
serverless in this hands-on session.
3
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Motivation for AWS Lambda
What is Serverless Computing?
What is AWS Lambda?
Hands-on with Examples
4
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What is Serverless Computing?
Architecture Paradigms
EC2 running behind
Load-Balancer
Container (ECS, EKS)
running behind Load-
Balancer
AWS Lambda running
behind API Gateway
5
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What is Serverless Computing?
Architecture Paradigms
EC2
• Machine as the unit of
scale
• Virtual servers in the cloud
• I configure machines,
storage, networking and
OS
ECS / EKS
• Application as the unit of
scale
• Container Management
Service for running Docker
containers
• Fargate (PaaS)
• I run container
management servers,
configure apps, control
scaling
Lambda
• Function as the unit of
scale
• Abstracts the language
runtime
• I run my code when it’s
needed
6
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• It’s hip, next to containerizing
apps:
(and good for staffing developers)
• Server Management:
• No servers to manage
• Continuous scaling
• No idle / cold servers
What is Serverless Computing?
Benefit of Serverless Applications
• Cost sensitive:
• Pay per request, low charge
• Buy compute time in mini
increments
• No hourly, daily or monthly
minimums
• No per-device fees
• Never pay for idle
7
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
The serverless compute manifesto
https://blog.rowanudell.com/the-serverless-compute-manifesto
! Functions are the unit of deployment and scaling.
! No machines, VMs, or containers visible in the programming model.
! Permanent storage lives elsewhere.
! Scales per request; Users cannot over- or under-provision capacity.
! Never pay for idle (no cold servers/containers or their costs).
! Implicitly fault-tolerant because functions can run anywhere.
! BYOC - Bring Your Own Code.
! Metrics and logging are a universal right.
8
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda API (Sources, Functions, Services)
Requests to endpoints
Changes in data state
Changes in resource state
• Go
• Python
• node.js
• Java
• Powershell Core
• C#
FUNCTION SERVICES (anything)EVENT SOURCE
TRIGGERS USES
List event sources / triggers: https://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html
Importance of IAM policies (attached to lambdas)
9
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Typical AWS Lambda Architecture
Amazon API
Gateway
Amazon
Cognito
IAM
Auth
Applications
Amazon
S3
Amazon
DynamoDB
Amazon
RDS
Amazon
ElastiCache
Data
Amazon
CloudWatch
Monitoring / Logging
AWS
Lambda
AWS Elastic
Beanstalk
AWS
CloudTrail
Amazon
SNS
10
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Using AWS Lambda
Bring your own code
• Multiple languages (Go, Python, Node.js, Java, Powershell Core, C#)
• Bring your own libraries
Simple resource model
• Select power rating based on memory size from 128 MB to 3000 MB
• CPU and network are allocated proportionally
• Reports / metrics actual usage
11
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Using AWS Lambda
Flexible use
• Call or send events
• Integrated with other AWS services
• Build server less ecosystems
Flexible authorization
• Securely grant access to resources, incl. VPCs
• Fine-grained control over who can call your function (Namespaces)
12
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Using AWS Lambda
Programming Model
• Built-in AWS SDK
• Front end is Lambda
Authoring functions
• Author directly using the Cloud9 editor (some kind with version control)
• Package code as a ZIP and upload to S3 / Lambda console
13
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Using AWS Lambda
Stateless
• Persist Data using DynamoDB, AWS Aurora Serverless, S3 or ElastiCache (states)
• No affinity to infrastructure (can’t login to host)
Monitoring and Logging
• Built in metrics for requests, latency, errors and throttles
• Built in logging with CloudWatch
14
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Lambda Pricing
• https://aws.amazon.com/lambda/pricing/
• Free tier: 1 million request, and 400’000 GB/s of compute
every month, for every customer
• AWS Lambda is cost effective when compared to EC2
• Keep in mind with AWS Lambda there is no infrastructure to
maintain
15
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
DEMO AND HANDS-ON TIME
16
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example 1 – TicTacToe
didactic approach - always start with something amusing
• AWS Lambda: Using in the GUI the
Serverless Application Repository
• Select: tic-tac-toe
• Learning how stuff works concretely from
examples
• Uses “poor-man-database” in filesystem
• Timeout is 180 seconds
AWS
Lambda
AWS cloud
Amazon API
Gateway
Browser 1
Browser 2
Amazon
CloudWatch
17
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example 1 – TicTacToe
didactic approach - always start with something amusing
18
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example 2 – Hello World with Versions and Aliases
implement best practices with an easy example
• AWS Lambda: Using in the GUI the
Serverless Application Repository
• Select: hello-world-python3
• Learning how to use versions and aliases
• Run 2 adapted versions of the same function
• … and split traffic to one of those two
instances
AWS
Lambda
AWS cloud
Amazon API
Gateway
AWS
Console
Amazon
CloudWatch
19
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example 3 – S3 as an Input Source
Dynamic Data Ingestion with Lambda + S3
Amazon
S3
AWS
Lambda
Amazon
DynamoDB
Amazon
S3
AWS cloud
OBJEC
T
Stores processed object to S3
Updates file metadata to DynamoDB
20
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example 3 – S3 as an Input Source
Dynamic Data Ingestion with Lambda + S3
1. Create S3 Bucket (e.g. YOURNAME-lambda-s3-upload)
2. Use s3-get-object-python3 blueprint with your bucket name
3. Upload a File with S3 Console
4. Have a look to the CloudWatch Logs
21
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
made of Lambda and EC2 instances
virtual private cloud PROD
AWS cloud Cust A
Service Host
(sh.vpc.example.com)
virtual private cloud STAGING
Service Host
(sh.vpc.example.com)
Amazon
Route 53
DDNS
Lambda
function
hosted zone
(vpc.example.com)
hosted zone
(vpc.example.com)
app
instances
app
instances
virtual private cloud PROD
AWS cloud Cust B
Service Host
(sh.vpc.example.com)
virtual private cloud STAGING
Service Host
(sh.vpc.example.com)
Amazon
Route 53
DDNS
Lambda
function
hosted zone
(vpc.example.com)
hosted zone
(vpc.example.com)
app
instances
app
instances
Solving a real life “problem”,
where the app servers
need a special common
but different gateway,
for each AWS account
and each AWS VPC context
22
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example 4 – Service Host local DNS resolution using DDNS
made of Lambda and EC2 instances
https://github.com/rplessl/aws-lambda-ddns
class ServiceHostLambdaDDns:
ZoneName = 'vpc.example.com.'
def __init__(self, event, context):
…
self.r53 = ServiceHostLambdaDDnsRoute53(ServiceHostLambdaDDns.ZoneName)
…
if self._state() == 'running':
ec2 = boto3.resource('ec2')
instance = ec2.Instance(self.instance_id())
target = instance.private_dns_name
self.r53.add_cname('sh', target)
self.r53.add_cname('*.sh', target)
23
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Example 5 – Using serverless framework (not SAM)
# see also serverless.com for documentation
# install node.js
brew install node.js
# install serverless framework
npm install -g serverless
# create node.js example and
serverless create --template aws-nodejs --path example1
cd example1
serverless deploy –v
serverless deploy function -f hello
serverless invoke -f hello –l
serverless logs -f hello –t
serverless remove
# improve example, see https://github.com/rplessl/aws-serverless-examples
# with https://docs.serverless.com and https://serverless-stack.com
24
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Lambda Best Practices (in general)
• Use Versions and Aliases in AWS Lambda Deployments
• AWS Lambda functions should be stateless
(focus: there will be used another sandbox)
• Using larger memory sizes will automatically provide more CPU
power
• Use CloudWatch to monitor AWS Lambda request latency
• Keep startup code to a minimum
• New instances can be started any time
25
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Lambda Best Practices (Testing)
• Use pipelines for coding with automated Tests
• Use mock’s for testing
• E.g. https://www.npmjs.com/package/aws-sdk-mock or https://github.com/spulec/moto
• Debug locally using
• AWS SAM Local
• Use small function parts
• Small functions with tests
• Extract functions to libraries
• Use Sample Event Data
• Prepare sample test events and document them
26
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Good Resources to Learn and Practice more with AWS
Lambda and Serverless
• Wild Rydes Serverless Workshops
Good full blown self-teaching workshops for
creating 5 different serverless use cases
https://github.com/aws-samples/aws-serverless-workshops
• Examples from the serverless toolkit
https://github.com/serverless/examples
27
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
And keep in mind!
“No server is easier to manage than no server”
@Werner, Re:Invent 2016
28
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Further Tools and Hints
29
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless Application Model
30
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What is the Serverless Application Model
• Typical applications consist of AWS services in addition to AWS
Lambda functions
implementation by hand can / will be error prone
• SAM
• uses CloudFormation to define all components of a serverless application
and architecture
• supports a simplified syntax for serverless resources (Lambda, API
Gateway, DynamoDB)
• supports the resources CloudFormation supports.
• blueprints in the AWS lambda console
31
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Step functions
When running complex functions the following must-be or questions arises:
• I will have sequential flow(s) of my functions
• I want to run functions in parallel
• I will use a third party app on a EC2 or a container
• I have code that runs for hours
AWS Step functions makes it easy to coordinate components of distributed
applications using a visual workflow.
Step function task can be on AWS Lambda, ECS or EC2.
32
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Further Tools and Integrations
• lambCI
Serverless continuous integration (like Travis or CircleCI)
https://github.com/lambci/lambci
including a CloudFormation Launch Stack
• lambda-packages
“How to integrate libraries with C bindings like python?...”
Various Python libraries precompiled and selected for using with AWS Lambda
https://github.com/Miserlou/lambda-packages
33
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Thank you!
Roman Plessl
github.com/rplessl
Reach us
nine, AWS Partner
www.nine.ch/en/aws
34

More Related Content

PDF
AWS Lambda Deep Dive
PPTX
Innovations fueled by IoT and the Cloud
PPTX
AWS Cloudformation Session 01
PPTX
AWS Batch: Simplifying batch computing in the cloud
PPTX
Being Well Architected in the Cloud (Updated)
PDF
AWS Lambda Supports Parallelization Factor for Kinesis and DynamoDB Event Sou...
PDF
Serverless use cases with AWS Lambda
PPTX
Getting started with Serverless on AWS
AWS Lambda Deep Dive
Innovations fueled by IoT and the Cloud
AWS Cloudformation Session 01
AWS Batch: Simplifying batch computing in the cloud
Being Well Architected in the Cloud (Updated)
AWS Lambda Supports Parallelization Factor for Kinesis and DynamoDB Event Sou...
Serverless use cases with AWS Lambda
Getting started with Serverless on AWS

Similar to AWSomeDay Zurich 2018 - How to go serverless (13)

PDF
Serverless Architectural Patterns 
and Best Practices - Madhu Shekar - AWS
PDF
Serverless Computing
PPTX
Serverless Architectural Patterns
PDF
Serverless architecture-patterns-and-best-practices
PPTX
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
PDF
Introduction to Serverless Computing and AWS Lambda - AWS IL Meetup
PDF
Genomics on aws-webinar-april2018
PDF
Building Serverless Microservices with AWS
PDF
AWS Application Service Workshop - Serverless Architecture
PDF
Serverless use cases with AWS Lambda - More Serverless Event
PPTX
Serverless Developer Experience I AWS Dev Day 2018
PPTX
AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...
PPTX
Serverless in Action on AWS
Serverless Architectural Patterns 
and Best Practices - Madhu Shekar - AWS
Serverless Computing
Serverless Architectural Patterns
Serverless architecture-patterns-and-best-practices
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Introduction to Serverless Computing and AWS Lambda - AWS IL Meetup
Genomics on aws-webinar-april2018
Building Serverless Microservices with AWS
AWS Application Service Workshop - Serverless Architecture
Serverless use cases with AWS Lambda - More Serverless Event
Serverless Developer Experience I AWS Dev Day 2018
AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...
Serverless in Action on AWS
Ad

Recently uploaded (20)

PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
DOC
Rose毕业证学历认证,利物浦约翰摩尔斯大学毕业证国外本科毕业证
PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPT
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PPTX
Internet___Basics___Styled_ presentation
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PDF
mera desh ae watn.(a source of motivation and patriotism to the youth of the ...
PDF
The Ikigai Template _ Recalibrate How You Spend Your Time.pdf
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPT
Ethics in Information System - Management Information System
PPTX
Mathew Digital SEO Checklist Guidlines 2025
PPTX
Introduction to cybersecurity and digital nettiquette
PPTX
artificialintelligenceai1-copy-210604123353.pptx
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PDF
Exploring VPS Hosting Trends for SMBs in 2025
DOCX
Unit-3 cyber security network security of internet system
PPTX
SAP Ariba Sourcing PPT for learning material
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
Rose毕业证学历认证,利物浦约翰摩尔斯大学毕业证国外本科毕业证
presentation_pfe-universite-molay-seltan.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
Power Point - Lesson 3_2.pptx grad school presentation
Internet___Basics___Styled_ presentation
The New Creative Director: How AI Tools for Social Media Content Creation Are...
mera desh ae watn.(a source of motivation and patriotism to the youth of the ...
The Ikigai Template _ Recalibrate How You Spend Your Time.pdf
Module 1 - Cyber Law and Ethics 101.pptx
Ethics in Information System - Management Information System
Mathew Digital SEO Checklist Guidlines 2025
Introduction to cybersecurity and digital nettiquette
artificialintelligenceai1-copy-210604123353.pptx
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
SASE Traffic Flow - ZTNA Connector-1.pdf
Exploring VPS Hosting Trends for SMBs in 2025
Unit-3 cyber security network security of internet system
SAP Ariba Sourcing PPT for learning material
Ad

AWSomeDay Zurich 2018 - How to go serverless

  • 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Zürich, AWSomeDay 12. September 2018 How to go serverless with AWS Lambda Roman Plessl, nine (AWS Partner)
  • 2. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. About myself and nine Roman Plessl Working for nine as a Solution Architect, Consultant and Leader. As a Cloud Navigator we offer you AWS Consulting, Migrations and also Operations. Besides nine I work as Consultant and Teacher (ETH, Foundation's) 2
  • 3. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Motivation for AWS Lambda With AWS Lambda you don’t need to worry about provisioning servers or scaling them. Learn which workloads work best and how to go serverless in this hands-on session. 3
  • 4. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Motivation for AWS Lambda What is Serverless Computing? What is AWS Lambda? Hands-on with Examples 4
  • 5. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. What is Serverless Computing? Architecture Paradigms EC2 running behind Load-Balancer Container (ECS, EKS) running behind Load- Balancer AWS Lambda running behind API Gateway 5
  • 6. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. What is Serverless Computing? Architecture Paradigms EC2 • Machine as the unit of scale • Virtual servers in the cloud • I configure machines, storage, networking and OS ECS / EKS • Application as the unit of scale • Container Management Service for running Docker containers • Fargate (PaaS) • I run container management servers, configure apps, control scaling Lambda • Function as the unit of scale • Abstracts the language runtime • I run my code when it’s needed 6
  • 7. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • It’s hip, next to containerizing apps: (and good for staffing developers) • Server Management: • No servers to manage • Continuous scaling • No idle / cold servers What is Serverless Computing? Benefit of Serverless Applications • Cost sensitive: • Pay per request, low charge • Buy compute time in mini increments • No hourly, daily or monthly minimums • No per-device fees • Never pay for idle 7
  • 8. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. The serverless compute manifesto https://blog.rowanudell.com/the-serverless-compute-manifesto ! Functions are the unit of deployment and scaling. ! No machines, VMs, or containers visible in the programming model. ! Permanent storage lives elsewhere. ! Scales per request; Users cannot over- or under-provision capacity. ! Never pay for idle (no cold servers/containers or their costs). ! Implicitly fault-tolerant because functions can run anywhere. ! BYOC - Bring Your Own Code. ! Metrics and logging are a universal right. 8
  • 9. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda API (Sources, Functions, Services) Requests to endpoints Changes in data state Changes in resource state • Go • Python • node.js • Java • Powershell Core • C# FUNCTION SERVICES (anything)EVENT SOURCE TRIGGERS USES List event sources / triggers: https://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html Importance of IAM policies (attached to lambdas) 9
  • 10. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Typical AWS Lambda Architecture Amazon API Gateway Amazon Cognito IAM Auth Applications Amazon S3 Amazon DynamoDB Amazon RDS Amazon ElastiCache Data Amazon CloudWatch Monitoring / Logging AWS Lambda AWS Elastic Beanstalk AWS CloudTrail Amazon SNS 10
  • 11. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Using AWS Lambda Bring your own code • Multiple languages (Go, Python, Node.js, Java, Powershell Core, C#) • Bring your own libraries Simple resource model • Select power rating based on memory size from 128 MB to 3000 MB • CPU and network are allocated proportionally • Reports / metrics actual usage 11
  • 12. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Using AWS Lambda Flexible use • Call or send events • Integrated with other AWS services • Build server less ecosystems Flexible authorization • Securely grant access to resources, incl. VPCs • Fine-grained control over who can call your function (Namespaces) 12
  • 13. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Using AWS Lambda Programming Model • Built-in AWS SDK • Front end is Lambda Authoring functions • Author directly using the Cloud9 editor (some kind with version control) • Package code as a ZIP and upload to S3 / Lambda console 13
  • 14. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Using AWS Lambda Stateless • Persist Data using DynamoDB, AWS Aurora Serverless, S3 or ElastiCache (states) • No affinity to infrastructure (can’t login to host) Monitoring and Logging • Built in metrics for requests, latency, errors and throttles • Built in logging with CloudWatch 14
  • 15. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Lambda Pricing • https://aws.amazon.com/lambda/pricing/ • Free tier: 1 million request, and 400’000 GB/s of compute every month, for every customer • AWS Lambda is cost effective when compared to EC2 • Keep in mind with AWS Lambda there is no infrastructure to maintain 15
  • 16. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. DEMO AND HANDS-ON TIME 16
  • 17. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example 1 – TicTacToe didactic approach - always start with something amusing • AWS Lambda: Using in the GUI the Serverless Application Repository • Select: tic-tac-toe • Learning how stuff works concretely from examples • Uses “poor-man-database” in filesystem • Timeout is 180 seconds AWS Lambda AWS cloud Amazon API Gateway Browser 1 Browser 2 Amazon CloudWatch 17
  • 18. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example 1 – TicTacToe didactic approach - always start with something amusing 18
  • 19. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example 2 – Hello World with Versions and Aliases implement best practices with an easy example • AWS Lambda: Using in the GUI the Serverless Application Repository • Select: hello-world-python3 • Learning how to use versions and aliases • Run 2 adapted versions of the same function • … and split traffic to one of those two instances AWS Lambda AWS cloud Amazon API Gateway AWS Console Amazon CloudWatch 19
  • 20. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example 3 – S3 as an Input Source Dynamic Data Ingestion with Lambda + S3 Amazon S3 AWS Lambda Amazon DynamoDB Amazon S3 AWS cloud OBJEC T Stores processed object to S3 Updates file metadata to DynamoDB 20
  • 21. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example 3 – S3 as an Input Source Dynamic Data Ingestion with Lambda + S3 1. Create S3 Bucket (e.g. YOURNAME-lambda-s3-upload) 2. Use s3-get-object-python3 blueprint with your bucket name 3. Upload a File with S3 Console 4. Have a look to the CloudWatch Logs 21
  • 22. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. made of Lambda and EC2 instances virtual private cloud PROD AWS cloud Cust A Service Host (sh.vpc.example.com) virtual private cloud STAGING Service Host (sh.vpc.example.com) Amazon Route 53 DDNS Lambda function hosted zone (vpc.example.com) hosted zone (vpc.example.com) app instances app instances virtual private cloud PROD AWS cloud Cust B Service Host (sh.vpc.example.com) virtual private cloud STAGING Service Host (sh.vpc.example.com) Amazon Route 53 DDNS Lambda function hosted zone (vpc.example.com) hosted zone (vpc.example.com) app instances app instances Solving a real life “problem”, where the app servers need a special common but different gateway, for each AWS account and each AWS VPC context 22
  • 23. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example 4 – Service Host local DNS resolution using DDNS made of Lambda and EC2 instances https://github.com/rplessl/aws-lambda-ddns class ServiceHostLambdaDDns: ZoneName = 'vpc.example.com.' def __init__(self, event, context): … self.r53 = ServiceHostLambdaDDnsRoute53(ServiceHostLambdaDDns.ZoneName) … if self._state() == 'running': ec2 = boto3.resource('ec2') instance = ec2.Instance(self.instance_id()) target = instance.private_dns_name self.r53.add_cname('sh', target) self.r53.add_cname('*.sh', target) 23
  • 24. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Example 5 – Using serverless framework (not SAM) # see also serverless.com for documentation # install node.js brew install node.js # install serverless framework npm install -g serverless # create node.js example and serverless create --template aws-nodejs --path example1 cd example1 serverless deploy –v serverless deploy function -f hello serverless invoke -f hello –l serverless logs -f hello –t serverless remove # improve example, see https://github.com/rplessl/aws-serverless-examples # with https://docs.serverless.com and https://serverless-stack.com 24
  • 25. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Lambda Best Practices (in general) • Use Versions and Aliases in AWS Lambda Deployments • AWS Lambda functions should be stateless (focus: there will be used another sandbox) • Using larger memory sizes will automatically provide more CPU power • Use CloudWatch to monitor AWS Lambda request latency • Keep startup code to a minimum • New instances can be started any time 25
  • 26. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Lambda Best Practices (Testing) • Use pipelines for coding with automated Tests • Use mock’s for testing • E.g. https://www.npmjs.com/package/aws-sdk-mock or https://github.com/spulec/moto • Debug locally using • AWS SAM Local • Use small function parts • Small functions with tests • Extract functions to libraries • Use Sample Event Data • Prepare sample test events and document them 26
  • 27. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Good Resources to Learn and Practice more with AWS Lambda and Serverless • Wild Rydes Serverless Workshops Good full blown self-teaching workshops for creating 5 different serverless use cases https://github.com/aws-samples/aws-serverless-workshops • Examples from the serverless toolkit https://github.com/serverless/examples 27
  • 28. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. And keep in mind! “No server is easier to manage than no server” @Werner, Re:Invent 2016 28
  • 29. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Further Tools and Hints 29
  • 30. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless Application Model 30
  • 31. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. What is the Serverless Application Model • Typical applications consist of AWS services in addition to AWS Lambda functions implementation by hand can / will be error prone • SAM • uses CloudFormation to define all components of a serverless application and architecture • supports a simplified syntax for serverless resources (Lambda, API Gateway, DynamoDB) • supports the resources CloudFormation supports. • blueprints in the AWS lambda console 31
  • 32. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Step functions When running complex functions the following must-be or questions arises: • I will have sequential flow(s) of my functions • I want to run functions in parallel • I will use a third party app on a EC2 or a container • I have code that runs for hours AWS Step functions makes it easy to coordinate components of distributed applications using a visual workflow. Step function task can be on AWS Lambda, ECS or EC2. 32
  • 33. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Further Tools and Integrations • lambCI Serverless continuous integration (like Travis or CircleCI) https://github.com/lambci/lambci including a CloudFormation Launch Stack • lambda-packages “How to integrate libraries with C bindings like python?...” Various Python libraries precompiled and selected for using with AWS Lambda https://github.com/Miserlou/lambda-packages 33
  • 34. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Thank you! Roman Plessl github.com/rplessl Reach us nine, AWS Partner www.nine.ch/en/aws 34