SlideShare uma empresa Scribd logo
1 de 49
Baixar para ler offline
Building Serverless
applications with Python
Andrii Soldatenko
8 April 2017
Italy, Otto
@a_soldatenko
Andrii Soldatenko
• Senior Python Developer at
• CTO at
• Co-organizer PyCon Belarus 2017
• Speaker at many PyCons and open
source contributor
• blogger at https://asoldatenko.com
@a_soldatenko
…in the next few years we’re going to
see the first billion-dollar startup with a
single employee, the founder, and that
engineer will be using serverless
technology.
@a_soldatenko
James Governor
Analyst & Co-founder at RedMonk
Origins of “Serverless”
@a_soldatenko
Origins of
http://readwrite.com/2012/10/15/why-the-future-of-software-
and-apps-is-serverless/
Travis CI
Later in 2014…
Amazon introduce
AWS Lambda
https://techcrunch.com/2015/11/24/aws-lamda-makes-
serverless-applications-a-reality/
What about conferences?
http://serverlessconf.io/
How Lambda works
@a_soldatenko
λ
@a_soldatenko
How Lambda works
@a_soldatenko
How Lambda works
- function name;
- memory size
- timeout;
- role;
@a_soldatenko
Your first λ function
def lambda_handler(event, context):
message = 'Hello {}!'.format(event['name'])
return {'message': message}
@a_soldatenko
Deploy λ function
#!/usr/bin/env bash
python -m zipfile -c hello_python.zip hello_python.py
aws lambda create-function 
--region us-west-2 
--function-name HelloPython 
--zip-file fileb://hello_python.zip 
--role arn:aws:iam::278117350010:role/lambda-s3-
execution-role 
--handler hello_python.my_handler 
--runtime python2.7 
--timeout 15 
--memory-size 512
@a_soldatenko
Invoke λ function
aws lambda invoke 
--function-name HelloPython 
--payload '{"name":"PyCon
Italy"}' output.txt
cat output.txt
{"message": "Hello PyCon Italy!"}%
@a_soldatenko
Amazon API Gateway
Resource HTTP verb
AWS
Lambda
/books GET get_books
/book POST create_book
/books/{ID} PUT chage_book
/books/{ID} DELETE delete_book
Chalice python
micro framework
https://github.com/awslabs/chalice
@a_soldatenko
Chalice python
micro framework
$ cat app.py

from chalice import Chalice
app = Chalice(app_name='hellopyconit')
@app.route('/books', methods=['GET'])
def get_books():
return {'hello': 'from python library'}

...

...
...
https://github.com/awslabs/chalice
...

...

...

@app.route('/books/{book_id}', methods=['POST', 'PUT', 'DELETE'])
def process_book(book_id):
request = app.current_request
if request.method == 'PUT':
return {'msg': 'Book {} changed'.format(book_id)}
elif request.method == 'DELETE':
return {'msg': 'Book {} deleted'.format(book_id)}
elif request.method == 'POST':
return {'msg': 'Book {} created'.format(book_id)}
Chalice python
micro framework
@a_soldatenko
Chalice deploy
chalice deploy
Updating IAM policy.
Updating lambda function...
Regen deployment package...
Sending changes to lambda.
API Gateway rest API already
found.
Deploying to: dev
https://8rxbsnge8d.execute-api.us-
west-2.amazonaws.com/dev/
@a_soldatenko
Try our books API
curl -XGET https://8rxbsnge8d.execute-
api.us-west-2.amazonaws.com/dev/books
{"hello": "from python library"}%
curl -XGET https://8rxbsnge8d.execute-
api.us-west-2.amazonaws.com/dev/books/15
{"message": "Book 15"}%
curl -XDELETE https://8rxbsnge8d.execute-
api.us-west-2.amazonaws.com/dev/books/15
{"message": "Book 15 has been deleted"}%
@a_soldatenko
Chalice under the hood
@a_soldatenko
- botocore;
- typing;
Chalice under the hood
@a_soldatenko
AWS Serverless
Application Model
@a_soldatenko
AWS SAM
@a_soldatenko
AWS lambda Limits
@a_soldatenko
AWS Lambda
without any costs
@a_soldatenko
- The first 400,000 seconds of
execution time with 1 GB of
memory
What if you want to run
your Django app?
@a_soldatenko
@a_soldatenko
@a_soldatenko
@a_soldatenko
And again what do you
mean “serveless”?
@a_soldatenko
➜ pip install zappa
➜ zappa init
███████╗ █████╗ ██████╗ ██████╗ █████╗
╚══███╔╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗
███╔╝ ███████║██████╔╝██████╔╝███████║
███╔╝ ██╔══██║██╔═══╝ ██╔═══╝ ██╔══██║
███████╗██║ ██║██║ ██║ ██║ ██║
╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝
Welcome to Zappa!
...
➜ zappa deploy
https://github.com/Miserlou/Zappa
@a_soldatenkohttps://github.com/Miserlou/Zappa
- deploy;
- tailing logs;
- run django manage.py

…
███████╗ █████╗ ██████╗ ██████╗ █████╗
╚══███╔╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗
███╔╝ ███████║██████╔╝██████╔╝███████║
███╔╝ ██╔══██║██╔═══╝ ██╔═══╝ ██╔══██║
███████╗██║ ██║██║ ██║ ██║ ██║
╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝
AWS lambda Limits
@a_soldatenko
Python 2.7
@a_soldatenko
Python 2.7 will retire
in...
@a_soldatenkohttps://pythonclock.org/
AWS lambda and
Python 3
@a_soldatenko
import os
def lambda_handler(event, context):
txt = open('/etc/issue')
print txt.read()
return {'message': txt.read()}
Amazon Linux AMI release 2016.03
Kernel r on an m
AWS lambda and
Python 3
@a_soldatenko
Linux ip-10-11-15-179 4.4.51-40.60.amzn1.x86_64 #1 SMP
Wed Mar 29 19:17:24 UTC 2017 x86_64 x86_64 x86_64 GNU/
Linux
import subprocess
def lambda_handler(event, context):
args = ('uname', '-a')
popen = subprocess.Popen(args,
stdout=subprocess.PIPE)
popen.wait()
output = popen.stdout.read()
print(output)
AWS lambda and
Python 3
@a_soldatenko
import subprocess
def lambda_handler(event, context):
args = ('which', 'python3')
popen = subprocess.Popen(args,
stdout=subprocess.PIPE)
popen.wait()
output = popen.stdout.read()
print(output)
python3: /usr/bin/python3 /usr/bin/python3.4m /usr/bin/
python3.4 /usr/lib/python3.4 /usr/lib64/python3.4 /usr/local/lib/
python3.4 /usr/include/python3.4m /usr/share/man/man1/
python3.1.gz
YAHOOO!!:
Run python 3 from
python 2
@a_soldatenko
Prepare Python 3 for
AWS Lambda
@a_soldatenko
virtualenv venv -p `which python3.4`
pip install requests
zip -r lambda_python3.zip venv
python3_program.py lambda.py
Run python 3 from
python 2
@a_soldatenko
cat lambda.py
import subprocess
def lambda_handler(event, context):
args = ('venv/bin/python3.4',
'python3_program.py')
popen = subprocess.Popen(args,
stdout=subprocess.PIPE)
popen.wait()
output = popen.stdout.read()
print(output)
Run python 3 from
python 2
@a_soldatenko
START RequestId: 44c89efb-1bd2-11e7-bf8c-83d444ed46f1
Version: $LATEST
Python 3.4.0
END RequestId: 44c89efb-1bd2-11e7-bf8c-83d444ed46f1
REPORT RequestId: 44c89efb-1bd2-11e7-bf8c-83d444ed46f1
Thanks Lyndon Swan
for ideas about hacking
python 3
@a_soldatenko
Future of serverless
@a_soldatenko
The biggest problem with Serverless FaaS right now is tooling.
Deployment / application bundling, configuration, monitoring /
logging, and debugging all need serious work.
https://github.com/awslabs/serverless-
application-model/blob/master/HOWTO.md
Thank You
andrii.soldatenko@toptal.com
https://asoldatenko.com
@a_soldatenko
Questions
? @a_soldatenko
We are hiring
https://www.toptal.com/#connect-
fantastic-computer-engineers

Mais conteúdo relacionado

Mais procurados

Helpful Automation Techniques - Selenium Camp 2014
Helpful Automation Techniques - Selenium Camp 2014Helpful Automation Techniques - Selenium Camp 2014
Helpful Automation Techniques - Selenium Camp 2014Justin Ison
 
Selenium conference, 2016
Selenium conference, 2016Selenium conference, 2016
Selenium conference, 2016Pooja Shah
 
SeConf_Nov2016_London
SeConf_Nov2016_LondonSeConf_Nov2016_London
SeConf_Nov2016_LondonPooja Shah
 
Engineering Tools at Netflix: Enabling Continuous Delivery
Engineering Tools at Netflix: Enabling Continuous DeliveryEngineering Tools at Netflix: Enabling Continuous Delivery
Engineering Tools at Netflix: Enabling Continuous DeliveryMike McGarr
 
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...Sauce Labs
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Hong Tat Yew
 
Selenium Testing on Chrome - Google DevFest Armenia 2015
Selenium Testing on Chrome - Google DevFest Armenia 2015Selenium Testing on Chrome - Google DevFest Armenia 2015
Selenium Testing on Chrome - Google DevFest Armenia 2015Sargis Sargsyan
 
Selenium Conference 2015 - Mobile Selenium Grid Setup
Selenium Conference 2015 - Mobile Selenium Grid SetupSelenium Conference 2015 - Mobile Selenium Grid Setup
Selenium Conference 2015 - Mobile Selenium Grid SetupJustin Ison
 
Selenium Camp 2016 - Kiev, Ukraine
Selenium Camp 2016 -  Kiev, UkraineSelenium Camp 2016 -  Kiev, Ukraine
Selenium Camp 2016 - Kiev, UkraineJustin Ison
 
Automation Best Practices
Automation Best PracticesAutomation Best Practices
Automation Best PracticesSauce Labs
 
Best Practices in Mobile CI (webinar)
Best Practices in Mobile CI (webinar)Best Practices in Mobile CI (webinar)
Best Practices in Mobile CI (webinar)Sauce Labs
 
Midwest PHP 2017 DevOps For Small team
Midwest PHP 2017 DevOps For Small teamMidwest PHP 2017 DevOps For Small team
Midwest PHP 2017 DevOps For Small teamJoe Ferguson
 
Moving From a Selenium Grid to the Cloud - A Real Life Story
Moving From a Selenium Grid to the Cloud - A Real Life StoryMoving From a Selenium Grid to the Cloud - A Real Life Story
Moving From a Selenium Grid to the Cloud - A Real Life StorySauce Labs
 
Continuous Testing in the Cloud
Continuous Testing in the CloudContinuous Testing in the Cloud
Continuous Testing in the CloudSauce Labs
 
Testing desktop apps with selenium
Testing desktop apps with seleniumTesting desktop apps with selenium
Testing desktop apps with seleniumFilip Braun
 
An Introduction to Appium Desktop
An Introduction to Appium DesktopAn Introduction to Appium Desktop
An Introduction to Appium DesktopSauce Labs
 
Belfast Selenium Meetup
Belfast Selenium MeetupBelfast Selenium Meetup
Belfast Selenium MeetupJustin Ison
 
Selenium and Sauce Labs
Selenium and Sauce LabsSelenium and Sauce Labs
Selenium and Sauce Labshugs
 

Mais procurados (20)

Helpful Automation Techniques - Selenium Camp 2014
Helpful Automation Techniques - Selenium Camp 2014Helpful Automation Techniques - Selenium Camp 2014
Helpful Automation Techniques - Selenium Camp 2014
 
Selenium conference, 2016
Selenium conference, 2016Selenium conference, 2016
Selenium conference, 2016
 
SeConf_Nov2016_London
SeConf_Nov2016_LondonSeConf_Nov2016_London
SeConf_Nov2016_London
 
Cypress workshop for JSFoo 2019
Cypress  workshop for JSFoo 2019Cypress  workshop for JSFoo 2019
Cypress workshop for JSFoo 2019
 
Engineering Tools at Netflix: Enabling Continuous Delivery
Engineering Tools at Netflix: Enabling Continuous DeliveryEngineering Tools at Netflix: Enabling Continuous Delivery
Engineering Tools at Netflix: Enabling Continuous Delivery
 
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...
Closer To the Metal - Why and How We Use XCTest and Espresso by Mario Negro P...
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)
 
Selenium Testing on Chrome - Google DevFest Armenia 2015
Selenium Testing on Chrome - Google DevFest Armenia 2015Selenium Testing on Chrome - Google DevFest Armenia 2015
Selenium Testing on Chrome - Google DevFest Armenia 2015
 
Selenium Conference 2015 - Mobile Selenium Grid Setup
Selenium Conference 2015 - Mobile Selenium Grid SetupSelenium Conference 2015 - Mobile Selenium Grid Setup
Selenium Conference 2015 - Mobile Selenium Grid Setup
 
Selenium Camp 2016 - Kiev, Ukraine
Selenium Camp 2016 -  Kiev, UkraineSelenium Camp 2016 -  Kiev, Ukraine
Selenium Camp 2016 - Kiev, Ukraine
 
Automation Best Practices
Automation Best PracticesAutomation Best Practices
Automation Best Practices
 
Best Practices in Mobile CI (webinar)
Best Practices in Mobile CI (webinar)Best Practices in Mobile CI (webinar)
Best Practices in Mobile CI (webinar)
 
Build Automation in Android
Build Automation in AndroidBuild Automation in Android
Build Automation in Android
 
Midwest PHP 2017 DevOps For Small team
Midwest PHP 2017 DevOps For Small teamMidwest PHP 2017 DevOps For Small team
Midwest PHP 2017 DevOps For Small team
 
Moving From a Selenium Grid to the Cloud - A Real Life Story
Moving From a Selenium Grid to the Cloud - A Real Life StoryMoving From a Selenium Grid to the Cloud - A Real Life Story
Moving From a Selenium Grid to the Cloud - A Real Life Story
 
Continuous Testing in the Cloud
Continuous Testing in the CloudContinuous Testing in the Cloud
Continuous Testing in the Cloud
 
Testing desktop apps with selenium
Testing desktop apps with seleniumTesting desktop apps with selenium
Testing desktop apps with selenium
 
An Introduction to Appium Desktop
An Introduction to Appium DesktopAn Introduction to Appium Desktop
An Introduction to Appium Desktop
 
Belfast Selenium Meetup
Belfast Selenium MeetupBelfast Selenium Meetup
Belfast Selenium Meetup
 
Selenium and Sauce Labs
Selenium and Sauce LabsSelenium and Sauce Labs
Selenium and Sauce Labs
 

Semelhante a Building serverless-applications

Building Serverless applications with Python
Building Serverless applications with PythonBuilding Serverless applications with Python
Building Serverless applications with PythonAndrii Soldatenko
 
Try! Swift Tokyo2017
Try! Swift Tokyo2017Try! Swift Tokyo2017
Try! Swift Tokyo2017Amy Cheong
 
Serverless in production, an experience report
Serverless in production, an experience reportServerless in production, an experience report
Serverless in production, an experience reportYan Cui
 
Serverless in Production, an experience report (AWS UG South Wales)
Serverless in Production, an experience report (AWS UG South Wales)Serverless in Production, an experience report (AWS UG South Wales)
Serverless in Production, an experience report (AWS UG South Wales)Yan Cui
 
DevOps + MongoDB Realm Serverless Functions = 🤩
DevOps + MongoDB Realm Serverless Functions = 🤩DevOps + MongoDB Realm Serverless Functions = 🤩
DevOps + MongoDB Realm Serverless Functions = 🤩Lauren Hayward Schaefer
 
Serverless in production, an experience report (CoDe-Conf)
Serverless in production, an experience report (CoDe-Conf)Serverless in production, an experience report (CoDe-Conf)
Serverless in production, an experience report (CoDe-Conf)Yan Cui
 
Serverless in production, an experience report (FullStack 2018)
Serverless in production, an experience report (FullStack 2018)Serverless in production, an experience report (FullStack 2018)
Serverless in production, an experience report (FullStack 2018)Yan Cui
 
Migrating Web SDK from JS to TS
Migrating Web SDK from JS to TSMigrating Web SDK from JS to TS
Migrating Web SDK from JS to TSGrigory Petrov
 
SoundCloud API Do:s and Don't:s
SoundCloud API Do:s and Don't:sSoundCloud API Do:s and Don't:s
SoundCloud API Do:s and Don't:sEric Wahlforss
 
Overboard.js - where are we going with with jsconfasia / devfestasia
Overboard.js - where are we going with with jsconfasia / devfestasiaOverboard.js - where are we going with with jsconfasia / devfestasia
Overboard.js - where are we going with with jsconfasia / devfestasiaChristian Heilmann
 
Building an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learnedBuilding an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learnedWojciech Koszek
 
SaaS Boilerplate.pptx
SaaS Boilerplate.pptxSaaS Boilerplate.pptx
SaaS Boilerplate.pptxDuyKhi8
 
Jets: The Ruby Serverless Framework Ruby Kaigi Japan 2019 April
Jets: The Ruby Serverless Framework Ruby Kaigi Japan 2019 AprilJets: The Ruby Serverless Framework Ruby Kaigi Japan 2019 April
Jets: The Ruby Serverless Framework Ruby Kaigi Japan 2019 AprilTung Nguyen
 
Understanding and building Your Own Docker
Understanding and building Your Own DockerUnderstanding and building Your Own Docker
Understanding and building Your Own DockerMotiejus Jakštys
 
Metasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #16: Safety on ATS language + MCUMetasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #16: Safety on ATS language + MCUKiwamu Okabe
 

Semelhante a Building serverless-applications (20)

Origins of Serverless
Origins of ServerlessOrigins of Serverless
Origins of Serverless
 
Building Serverless applications with Python
Building Serverless applications with PythonBuilding Serverless applications with Python
Building Serverless applications with Python
 
Try! Swift Tokyo2017
Try! Swift Tokyo2017Try! Swift Tokyo2017
Try! Swift Tokyo2017
 
Serverless in production, an experience report
Serverless in production, an experience reportServerless in production, an experience report
Serverless in production, an experience report
 
Serverless in Production, an experience report (AWS UG South Wales)
Serverless in Production, an experience report (AWS UG South Wales)Serverless in Production, an experience report (AWS UG South Wales)
Serverless in Production, an experience report (AWS UG South Wales)
 
DevOps + MongoDB Realm Serverless Functions = 🤩
DevOps + MongoDB Realm Serverless Functions = 🤩DevOps + MongoDB Realm Serverless Functions = 🤩
DevOps + MongoDB Realm Serverless Functions = 🤩
 
Serverless in production, an experience report (CoDe-Conf)
Serverless in production, an experience report (CoDe-Conf)Serverless in production, an experience report (CoDe-Conf)
Serverless in production, an experience report (CoDe-Conf)
 
Serverless in production, an experience report (FullStack 2018)
Serverless in production, an experience report (FullStack 2018)Serverless in production, an experience report (FullStack 2018)
Serverless in production, an experience report (FullStack 2018)
 
DevOps + MongoDB Serverless = 
DevOps + MongoDB Serverless = DevOps + MongoDB Serverless = 
DevOps + MongoDB Serverless = 
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Migrating Web SDK from JS to TS
Migrating Web SDK from JS to TSMigrating Web SDK from JS to TS
Migrating Web SDK from JS to TS
 
SoundCloud API Do:s and Don't:s
SoundCloud API Do:s and Don't:sSoundCloud API Do:s and Don't:s
SoundCloud API Do:s and Don't:s
 
API-First Design and Django
API-First Design and DjangoAPI-First Design and Django
API-First Design and Django
 
Overboard.js - where are we going with with jsconfasia / devfestasia
Overboard.js - where are we going with with jsconfasia / devfestasiaOverboard.js - where are we going with with jsconfasia / devfestasia
Overboard.js - where are we going with with jsconfasia / devfestasia
 
Kiwipycon command line
Kiwipycon command lineKiwipycon command line
Kiwipycon command line
 
Building an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learnedBuilding an Open Source iOS app: lessons learned
Building an Open Source iOS app: lessons learned
 
SaaS Boilerplate.pptx
SaaS Boilerplate.pptxSaaS Boilerplate.pptx
SaaS Boilerplate.pptx
 
Jets: The Ruby Serverless Framework Ruby Kaigi Japan 2019 April
Jets: The Ruby Serverless Framework Ruby Kaigi Japan 2019 AprilJets: The Ruby Serverless Framework Ruby Kaigi Japan 2019 April
Jets: The Ruby Serverless Framework Ruby Kaigi Japan 2019 April
 
Understanding and building Your Own Docker
Understanding and building Your Own DockerUnderstanding and building Your Own Docker
Understanding and building Your Own Docker
 
Metasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #16: Safety on ATS language + MCUMetasepi team meeting #16: Safety on ATS language + MCU
Metasepi team meeting #16: Safety on ATS language + MCU
 

Mais de Andrii Soldatenko

Debugging concurrency programs in go
Debugging concurrency programs in goDebugging concurrency programs in go
Debugging concurrency programs in goAndrii Soldatenko
 
Building robust and friendly command line applications in go
Building robust and friendly command line applications in goBuilding robust and friendly command line applications in go
Building robust and friendly command line applications in goAndrii Soldatenko
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAndrii Soldatenko
 
Building social network with Neo4j and Python
Building social network with Neo4j and PythonBuilding social network with Neo4j and Python
Building social network with Neo4j and PythonAndrii Soldatenko
 
What is the best full text search engine for Python?
What is the best full text search engine for Python?What is the best full text search engine for Python?
What is the best full text search engine for Python?Andrii Soldatenko
 
PyCon Russian 2015 - Dive into full text search with python.
PyCon Russian 2015 - Dive into full text search with python.PyCon Russian 2015 - Dive into full text search with python.
PyCon Russian 2015 - Dive into full text search with python.Andrii Soldatenko
 
PyCon 2015 Belarus Andrii Soldatenko
PyCon 2015 Belarus Andrii SoldatenkoPyCon 2015 Belarus Andrii Soldatenko
PyCon 2015 Belarus Andrii SoldatenkoAndrii Soldatenko
 

Mais de Andrii Soldatenko (8)

Debugging concurrency programs in go
Debugging concurrency programs in goDebugging concurrency programs in go
Debugging concurrency programs in go
 
Building robust and friendly command line applications in go
Building robust and friendly command line applications in goBuilding robust and friendly command line applications in go
Building robust and friendly command line applications in go
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
 
Building social network with Neo4j and Python
Building social network with Neo4j and PythonBuilding social network with Neo4j and Python
Building social network with Neo4j and Python
 
What is the best full text search engine for Python?
What is the best full text search engine for Python?What is the best full text search engine for Python?
What is the best full text search engine for Python?
 
Kyiv.py #16 october 2015
Kyiv.py #16 october 2015Kyiv.py #16 october 2015
Kyiv.py #16 october 2015
 
PyCon Russian 2015 - Dive into full text search with python.
PyCon Russian 2015 - Dive into full text search with python.PyCon Russian 2015 - Dive into full text search with python.
PyCon Russian 2015 - Dive into full text search with python.
 
PyCon 2015 Belarus Andrii Soldatenko
PyCon 2015 Belarus Andrii SoldatenkoPyCon 2015 Belarus Andrii Soldatenko
PyCon 2015 Belarus Andrii Soldatenko
 

Último

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 

Último (20)

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

Building serverless-applications

  • 1. Building Serverless applications with Python Andrii Soldatenko 8 April 2017 Italy, Otto @a_soldatenko
  • 2. Andrii Soldatenko • Senior Python Developer at • CTO at • Co-organizer PyCon Belarus 2017 • Speaker at many PyCons and open source contributor • blogger at https://asoldatenko.com @a_soldatenko
  • 3. …in the next few years we’re going to see the first billion-dollar startup with a single employee, the founder, and that engineer will be using serverless technology. @a_soldatenko James Governor Analyst & Co-founder at RedMonk
  • 7.
  • 8. Later in 2014… Amazon introduce AWS Lambda https://techcrunch.com/2015/11/24/aws-lamda-makes- serverless-applications-a-reality/
  • 13. How Lambda works - function name; - memory size - timeout; - role; @a_soldatenko
  • 14. Your first λ function def lambda_handler(event, context): message = 'Hello {}!'.format(event['name']) return {'message': message} @a_soldatenko
  • 15. Deploy λ function #!/usr/bin/env bash python -m zipfile -c hello_python.zip hello_python.py aws lambda create-function --region us-west-2 --function-name HelloPython --zip-file fileb://hello_python.zip --role arn:aws:iam::278117350010:role/lambda-s3- execution-role --handler hello_python.my_handler --runtime python2.7 --timeout 15 --memory-size 512 @a_soldatenko
  • 16. Invoke λ function aws lambda invoke --function-name HelloPython --payload '{"name":"PyCon Italy"}' output.txt cat output.txt {"message": "Hello PyCon Italy!"}% @a_soldatenko
  • 17. Amazon API Gateway Resource HTTP verb AWS Lambda /books GET get_books /book POST create_book /books/{ID} PUT chage_book /books/{ID} DELETE delete_book
  • 19. Chalice python micro framework $ cat app.py
 from chalice import Chalice app = Chalice(app_name='hellopyconit') @app.route('/books', methods=['GET']) def get_books(): return {'hello': 'from python library'}
 ...
 ... ... https://github.com/awslabs/chalice
  • 20. ...
 ...
 ...
 @app.route('/books/{book_id}', methods=['POST', 'PUT', 'DELETE']) def process_book(book_id): request = app.current_request if request.method == 'PUT': return {'msg': 'Book {} changed'.format(book_id)} elif request.method == 'DELETE': return {'msg': 'Book {} deleted'.format(book_id)} elif request.method == 'POST': return {'msg': 'Book {} created'.format(book_id)} Chalice python micro framework @a_soldatenko
  • 21. Chalice deploy chalice deploy Updating IAM policy. Updating lambda function... Regen deployment package... Sending changes to lambda. API Gateway rest API already found. Deploying to: dev https://8rxbsnge8d.execute-api.us- west-2.amazonaws.com/dev/ @a_soldatenko
  • 22. Try our books API curl -XGET https://8rxbsnge8d.execute- api.us-west-2.amazonaws.com/dev/books {"hello": "from python library"}% curl -XGET https://8rxbsnge8d.execute- api.us-west-2.amazonaws.com/dev/books/15 {"message": "Book 15"}% curl -XDELETE https://8rxbsnge8d.execute- api.us-west-2.amazonaws.com/dev/books/15 {"message": "Book 15 has been deleted"}% @a_soldatenko
  • 23. Chalice under the hood @a_soldatenko - botocore; - typing;
  • 24. Chalice under the hood @a_soldatenko
  • 28. AWS Lambda without any costs @a_soldatenko - The first 400,000 seconds of execution time with 1 GB of memory
  • 29. What if you want to run your Django app? @a_soldatenko
  • 32. @a_soldatenko And again what do you mean “serveless”?
  • 33. @a_soldatenko ➜ pip install zappa ➜ zappa init ███████╗ █████╗ ██████╗ ██████╗ █████╗ ╚══███╔╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗ ███╔╝ ███████║██████╔╝██████╔╝███████║ ███╔╝ ██╔══██║██╔═══╝ ██╔═══╝ ██╔══██║ ███████╗██║ ██║██║ ██║ ██║ ██║ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ Welcome to Zappa! ... ➜ zappa deploy https://github.com/Miserlou/Zappa
  • 34. @a_soldatenkohttps://github.com/Miserlou/Zappa - deploy; - tailing logs; - run django manage.py
 … ███████╗ █████╗ ██████╗ ██████╗ █████╗ ╚══███╔╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗ ███╔╝ ███████║██████╔╝██████╔╝███████║ ███╔╝ ██╔══██║██╔═══╝ ██╔═══╝ ██╔══██║ ███████╗██║ ██║██║ ██║ ██║ ██║ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝
  • 37. Python 2.7 will retire in... @a_soldatenkohttps://pythonclock.org/
  • 38. AWS lambda and Python 3 @a_soldatenko import os def lambda_handler(event, context): txt = open('/etc/issue') print txt.read() return {'message': txt.read()} Amazon Linux AMI release 2016.03 Kernel r on an m
  • 39. AWS lambda and Python 3 @a_soldatenko Linux ip-10-11-15-179 4.4.51-40.60.amzn1.x86_64 #1 SMP Wed Mar 29 19:17:24 UTC 2017 x86_64 x86_64 x86_64 GNU/ Linux import subprocess def lambda_handler(event, context): args = ('uname', '-a') popen = subprocess.Popen(args, stdout=subprocess.PIPE) popen.wait() output = popen.stdout.read() print(output)
  • 40. AWS lambda and Python 3 @a_soldatenko import subprocess def lambda_handler(event, context): args = ('which', 'python3') popen = subprocess.Popen(args, stdout=subprocess.PIPE) popen.wait() output = popen.stdout.read() print(output) python3: /usr/bin/python3 /usr/bin/python3.4m /usr/bin/ python3.4 /usr/lib/python3.4 /usr/lib64/python3.4 /usr/local/lib/ python3.4 /usr/include/python3.4m /usr/share/man/man1/ python3.1.gz YAHOOO!!:
  • 41. Run python 3 from python 2 @a_soldatenko
  • 42. Prepare Python 3 for AWS Lambda @a_soldatenko virtualenv venv -p `which python3.4` pip install requests zip -r lambda_python3.zip venv python3_program.py lambda.py
  • 43. Run python 3 from python 2 @a_soldatenko cat lambda.py import subprocess def lambda_handler(event, context): args = ('venv/bin/python3.4', 'python3_program.py') popen = subprocess.Popen(args, stdout=subprocess.PIPE) popen.wait() output = popen.stdout.read() print(output)
  • 44. Run python 3 from python 2 @a_soldatenko START RequestId: 44c89efb-1bd2-11e7-bf8c-83d444ed46f1 Version: $LATEST Python 3.4.0 END RequestId: 44c89efb-1bd2-11e7-bf8c-83d444ed46f1 REPORT RequestId: 44c89efb-1bd2-11e7-bf8c-83d444ed46f1
  • 45. Thanks Lyndon Swan for ideas about hacking python 3 @a_soldatenko
  • 46. Future of serverless @a_soldatenko The biggest problem with Serverless FaaS right now is tooling. Deployment / application bundling, configuration, monitoring / logging, and debugging all need serious work. https://github.com/awslabs/serverless- application-model/blob/master/HOWTO.md