SlideShare a Scribd company logo
Writing and deploying serverless
Python applications
César Cárdenas Desales
PyCon Ireland, October 2017
About me
Software Architect at Webrepublic AG
Python User since v.2.0
Co-organizer of the Swiss Python Summit (next on Feb. 2018)
Coorganizer of the Zurich Python User Group
@ccdesales
Intro What is it?
Architecture Archeology - Client server
A fat do-it-all Server
Mostly on-premises server
Upfront investment
Capacity planning
Scaling was a nightmare
Cloud based architectures
+ Servers can be disposable, unless
they’re snowflakes
+ Application architecture can make
scaling easier or more difficult
- Capacity planning still required
- Still pay ($$) if your server is idle
Capacity planning
How many servers?
How powerful?
How much memory?
What do we do with excess resources?
What if we have too little resources?
How do we (dynamically) grow or shrink resources?
Resources become obsolete
What if we suffer the Slashdot effect?
Serverless: a very simple yet powerful idea
● You submit units of work for execution
● Pay only for computing time you consume
Serverless: Well, there’s actually a server...
What does Serverless mean for you?
● Less Work
○ No need to run servers in premises
○ No need to manage servers in the cloud (admin, patches)
○ No need to plan capacity or scaling
● Potential money savings
○ Only pay for computing time you use
Why does it make me excited
● I’m an aging developer
Why does serverless make me excited?
● I’m an aging developer
● Potentially unlimited scaling
● Computing resources are
disposable
● Low level maintenance is
abstracted out…
● (it’s somebody else’s problem)
● IT assets are programmable
Serverless with AWS Lambda
AWS Lambda
● Amazon Web Services’ serverless platform
Supported technologies
Choose
template
Choose
trigger
Add config
& code
Test
Write
client
The process
Choose
template
Choose
trigger
Add config
& code
Test
Write
client
Choose template
Choose template
Choose
template
Choose
trigger
Add config
& code
Test
Write
client
Choose trigger
Choose
template
Choose
trigger
Add config
& code
Test
Write
client
Add config & code
● Upload .ZIP file
● Upload file from
Amazon S3
Add config & code
● VPC
● Env variables
● Security roles
Max. 300 secs
Choose
template
Choose
trigger
Add config
& code
Test
Write
client
Test
Test
PyConIE 2017 Writing and deploying serverless python applications
Choose
template
Choose
trigger
Add config
& code
Test
Write
client
Client
Output - synchronous call
Output - Asynchronous call
Precondition to run the exercises
tree ~/.aws cat ~/.aws/config
[default]
region = eu-west-1
cat ~/.aws/credentials
[default]
aws_access_key_id = SOME_ID
aws_secret_access_key = AKEY
Serverless the
easy way:
Zappa
What is zappa?
● A python framework for serverless applications
● Used as command line tool
● Manages application lifecycle
○ Creation
○ Deploy
○ Update
○ Undeploy Configure Deploy Test
pip install zappa
● Installs latest zappa
Configure Deploy Test
zappa init
● Optional
● Initializes project
● Creates zappa_settings.json file
● YAML format also available
Configure Deploy Test
Zappa code looks like Flask
● example.py
● zappa_settings.json
Configure Deploy Test
zappa deploy dev
Calling deploy for stage dev..
Downloading and installing dependencies..
Packaging project as zip.
Uploading servless-dev-1506419080.zip (5.9MiB)..
100%|███████████████| 6.16M/6.16M [00:01<00:00, 2.16MB/s]
Scheduling..
Scheduled servless-dev-zappa-keep-warm-handler.keep_warm_callback
with expression rate(4 minutes)!
TestConfigure Deploy Test
zappa deploy dev
Uploading servless-dev-template-1506419092.json (1.6KiB)..
100%|███████████████| 1.61K/1.61K [00:00<00:00, 3.71KB/s]
Waiting for stack servless-dev to create (this can take a bit)..
75%|███████████▎ | 3/4 [00:09<00:04, 4.94s/res]
Deploying API Gateway..
Deployment complete!:
https://x0doi1ioid.execute-api.eu-west-1.amazonaws.com/dev
TestConfigure Deploy Test
zappa deploy dev
Uploading servless-dev-template-1506419092.json (1.6KiB)..
100%|███████████████| 1.61K/1.61K [00:00<00:00, 3.71KB/s]
Waiting for stack servless-dev to create (this can take a bit)..
75%|███████████▎ | 3/4 [00:09<00:04, 4.94s/res]
Deploying API Gateway..
Deployment complete!:
https://x0doi1ioid.execute-api.eu-west-1.amazonaws.com/dev
TestConfigure Deploy Test
TestConfigure Deploy Test
Restful API
Boto3
curl https://x0doi1ioid.execute-api.eu-west-1.amazonaws.com/dev
hello from Flask
TestConfigure Deploy Test
Other commands
zappa tail
● Show latest logs
zappa update dev
● Update code and
settings
zappa undeploy dev
● Remove lambda
function
● Remove AWS API
Gateway
Zappa creates and deploys the Lambda
Zappa goodies
● Creates deployment package (modules from current virtualenv)
● Performs deployments (no manual *.zip uploads)
● Support for stages (dev, stage, prod)
● Manages settings:
○ Environment variables
○ Logging (AWS CloudWatch)
○ Domain names
○ VPC
○ Security roles
○ Certificates and keys
● API creation
Zappa creates a (AWS API Gateway) RESTful API
Why API Gateway?
● Interoperability
○ It’s only JSON over HTTP
○ Other platforms
○ Other AWS technologies
○ Other languages
○ Clients not tied to boto
● RESTful API
● Request Throttling/Limits
● Authorization tokens
Pitfalls & tips
Pitfalls
● 300 seconds execution time limit
● Calls must be stateless
● Cold start for 1st request -> Keep warm calls
○ An computing instance must be started
○ Can also happen during low traffic periods
● Logging only to CloudWatch
Pitfalls
● Fragmentation in a myriad of microservices
● No (DB) connection pooling
● Data potentially leaves your country
● Flame wars
○ 1 (Git) repository per service
○ All services in 1 (Git) repository
● Potential vendor lock-in
● Flow control and error handling gets tricky
AWS Steps Functions - Orchestration
Diagram Amazon States Language
The upsell - AWS Steps Functions
Geography matters
● Regions
● Availability
zones
● Edge locations
Content Delivery Networks
● AWS CloudFront: Amazon’s CDN
● Content served by edge location
closest to client
○ Images
○ Pages
○ Streams
Edge Locations
● AWS CloudFront: Amazon’s CDN
● Content served by edge location
closest to client
○ Images
○ Pages
○ Streams
Lambda Functions deployed into Regions
● Or, into a EC2 instance < AZ < Region
● High latency on requests from distant
areas
AWS Lambda@Edge
● Lambdas deployed to edge
locations
● Requests to Lambdas served by
closest (edge) location
AWS Lambda pricing
Free tier
First dosis is free
AWS Lambda pricing
Requests
First 1 million requests
per month are free
$0.20 per 1 million
requests thereafter
($0.0000002 per request)
Duration
Billing rounded up to the
nearest 100ms
Depending on the
amount of allocated
memory
Other
Data transfer (external)
Data storage
AWS API Gateway, $3.50
per million API calls
received
Alternatives
Vendor
Google Cloud Functions
(Beta, only JS, no env
vars)
Microsoft Azure
Functions
Python libs
Chalice
Apex
Vendor agnostic
The Serverless
framework
https://goo.gl/yYh2M4
Shameless plug
● Swiss Python Summit 2018
● February 16th, 2018
● Close to Zurich
● CFP still open
● www.python-summit.ch
Thank
@ccdesales
https://github.com/ccdesales/serverless_examples
you!

More Related Content

PDF
PyConIT 2018 Writing and deploying serverless python applications
PDF
Writing and deploying serverless python applications
PDF
Universal Serverless with AWS Fargate
PDF
Netty training
PDF
PDF
The benefits of running Spark on your own Docker
PDF
NetflixOSS Meetup season 3 episode 1
PPTX
Lamba scaffold webinar
PyConIT 2018 Writing and deploying serverless python applications
Writing and deploying serverless python applications
Universal Serverless with AWS Fargate
Netty training
The benefits of running Spark on your own Docker
NetflixOSS Meetup season 3 episode 1
Lamba scaffold webinar

What's hot (20)

PDF
Deliver Docker Containers Continuously On AWS - DevOpsCon Munich 2016
PPTX
Local Lambda Debugging
PPTX
Nashorn: JavaScript that doesn't suck - Tomer Gabel, Wix
PDF
From Three Nines to Five Nines - A Kafka Journey
PDF
Andrew Nelson - Zabbix and SNMP on Linux
PPTX
Honest Performance Testing with "NDBench" (Vinay Chella, Netflix) | Cassandra...
PDF
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
PDF
Clouds presentation, aws meetup v2
PDF
USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a Month
PDF
Netflix Keystone - How Netflix Handles Data Streams up to 11M Events/Sec
PDF
Uber Real Time Data Analytics
PDF
Tracing Microservices with Zipkin
PDF
High Performance Systems in Go - GopherCon 2014
PDF
Docker primer and tips
PPTX
Hadoop Meetup Jan 2019 - TonY: TensorFlow on YARN and Beyond
PDF
Azure Functions - Get rid of your servers, use functions!
PPTX
Riga dev day: Lambda architecture at AWS
PDF
Unbounded bounded-data-strangeloop-2016-monal-daxini
PDF
Building a distributed Key-Value store with Cassandra
PDF
Measure and Increase Developer Productivity with Help of Serverless at JCON 2...
Deliver Docker Containers Continuously On AWS - DevOpsCon Munich 2016
Local Lambda Debugging
Nashorn: JavaScript that doesn't suck - Tomer Gabel, Wix
From Three Nines to Five Nines - A Kafka Journey
Andrew Nelson - Zabbix and SNMP on Linux
Honest Performance Testing with "NDBench" (Vinay Chella, Netflix) | Cassandra...
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
Clouds presentation, aws meetup v2
USENIX LISA15: How TubeMogul Handles over One Trillion HTTP Requests a Month
Netflix Keystone - How Netflix Handles Data Streams up to 11M Events/Sec
Uber Real Time Data Analytics
Tracing Microservices with Zipkin
High Performance Systems in Go - GopherCon 2014
Docker primer and tips
Hadoop Meetup Jan 2019 - TonY: TensorFlow on YARN and Beyond
Azure Functions - Get rid of your servers, use functions!
Riga dev day: Lambda architecture at AWS
Unbounded bounded-data-strangeloop-2016-monal-daxini
Building a distributed Key-Value store with Cassandra
Measure and Increase Developer Productivity with Help of Serverless at JCON 2...
Ad

Similar to PyConIE 2017 Writing and deploying serverless python applications (20)

PDF
Čtvrtkon #64 - AWS Serverless - Michal Haták
PDF
«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...
PDF
Microservices and Serverless for Mega Startups - DevOps IL Meetup
PDF
AWSomeDay Zurich 2018 - How to go serverless
PDF
Python in the Serverless Era (PyCon IL 2016)
PDF
Introduction to Serverless Computing and AWS Lambda - AWS IL Meetup
PDF
Building serverless-applications
PPTX
Primeros pasos en desarrollo serverless
PDF
Serverless use cases with AWS Lambda - More Serverless Event
PDF
Serverless Node.js
PDF
用Serverless技術快速開發line聊天機器人
PDF
Jumpstart your idea with AWS Serverless [Oct 2020]
POTX
Serverless: State of The Union I AWS Dev Day 2018
PDF
Serverless Computing
PDF
AWS Application Service Workshop - Serverless Architecture
PDF
Building serverless applications (April 2018)
PDF
Python in the land of serverless
PDF
Building Serverless Microservices with AWS
PDF
2022 Presentation | Serverless Innovation with AWS
PDF
Serverless use cases with AWS Lambda
Čtvrtkon #64 - AWS Serverless - Michal Haták
«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...
Microservices and Serverless for Mega Startups - DevOps IL Meetup
AWSomeDay Zurich 2018 - How to go serverless
Python in the Serverless Era (PyCon IL 2016)
Introduction to Serverless Computing and AWS Lambda - AWS IL Meetup
Building serverless-applications
Primeros pasos en desarrollo serverless
Serverless use cases with AWS Lambda - More Serverless Event
Serverless Node.js
用Serverless技術快速開發line聊天機器人
Jumpstart your idea with AWS Serverless [Oct 2020]
Serverless: State of The Union I AWS Dev Day 2018
Serverless Computing
AWS Application Service Workshop - Serverless Architecture
Building serverless applications (April 2018)
Python in the land of serverless
Building Serverless Microservices with AWS
2022 Presentation | Serverless Innovation with AWS
Serverless use cases with AWS Lambda
Ad

More from Cesar Cardenas Desales (7)

PDF
Migrate to Python 3 using the six library
PDF
Scalable Web applications with Elastic Beanstalk as your PAAS: a primer
PDF
Software maintenance PyConPL 2016
PPTX
Unit Testing with Nose
PDF
Distributed Task Processing with Celery - PyZH
PDF
Software maintenance PyConUK 2016
PDF
Code Reviews in Python - PyZh
Migrate to Python 3 using the six library
Scalable Web applications with Elastic Beanstalk as your PAAS: a primer
Software maintenance PyConPL 2016
Unit Testing with Nose
Distributed Task Processing with Celery - PyZH
Software maintenance PyConUK 2016
Code Reviews in Python - PyZh

Recently uploaded (20)

PDF
System and Network Administration Chapter 2
PPTX
assetexplorer- product-overview - presentation
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
L1 - Introduction to python Backend.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
ai tools demonstartion for schools and inter college
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
top salesforce developer skills in 2025.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
history of c programming in notes for students .pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPT
Introduction Database Management System for Course Database
System and Network Administration Chapter 2
assetexplorer- product-overview - presentation
Operating system designcfffgfgggggggvggggggggg
Adobe Illustrator 28.6 Crack My Vision of Vector Design
L1 - Introduction to python Backend.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Softaken Excel to vCard Converter Software.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
ai tools demonstartion for schools and inter college
Reimagine Home Health with the Power of Agentic AI​
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
top salesforce developer skills in 2025.pdf
CHAPTER 2 - PM Management and IT Context
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Design an Analysis of Algorithms I-SECS-1021-03
PTS Company Brochure 2025 (1).pdf.......
history of c programming in notes for students .pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
Introduction Database Management System for Course Database

PyConIE 2017 Writing and deploying serverless python applications