SlideShare a Scribd company logo
Building Serverless
applications with Python3
Andrii Soldatenko
12 June 2017
@a_soldatenko
Andrii
Soldatenko
• Senior Python Developer at Toptal
• Speaker at many PyCons and open
source contributor
• blogger at https://asoldatenko.com
@a_soldatenko
cat /etc/passwd
…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 announced
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
@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
@a_soldatenko
From Apr 18, 2017 AWS Lambda
Supports Python 3.6
Face detection
Example:
Using binaries with your
function
yum update -y
yum install -y git cmake gcc-c++ gcc python-
devel chrpath
mkdir -p lambda-package/cv2 build/numpy
...
pip install opencv-python -t .
...
# Copy template function and zip package
cp template.py lambda-package/lambda_function.py
cd lambda-package
zip -r ../lambda-package.zip *
Prepare wheels
import cv2
def lambda_handler(event, context):
print(“OpenCV installed version:",
cv2.__version__)
return "It works!"
lambda function
START RequestId: 19e6a8f9-4eea-11e7-a662-299188c47179
Version: $LATEST
OpenCV installed version: 3.2.0
END RequestId: 19e6a8f9-4eea-11e7-a662-299188c47179
REPORT RequestId: 19e6a8f9-4eea-11e7-
a662-299188c47179 Duration: 0.46 ms Billed Duration: 100
ms Memory Size: 512 MB Max Memory Used: 35 MB
import importlib
import sys
# Import your lambda python module
mod = importlib.import_module(sys.argv[1])
function_handler = sys.argv[2]
lambda_function = getattr(mod, function_handler )
event = {'name': 'Andrii'}
context = {'conference_name': 'PyCon Israel'}
try:
data = function_handler(event, context)
print(data)
except Exception as error:
print(error)
How to run lambda
locally
$ python local_lambda.py lambda_function lambda_handler
{'message': 'Hello Andrii!'}
How to run lambda
locally
What about
websockets?
A: No, API Gateway doesn’t
support
https://forums.aws.amazon.com/thread.jspa?threadID=205761
AWS IoT Now Supports
WebSockets
http://stesie.github.io/2016/04/aws-iot-pubsub
Thank You
https://asoldatenko.com

@a_soldatenko
Questions
? @a_soldatenko
We are hiring
https://www.toptal.com/#connect-
fantastic-computer-engineers

More Related Content

What's hot

3h à l'assaut d'une application réactive - Devoxx 2015
3h à l'assaut d'une application réactive - Devoxx 20153h à l'assaut d'une application réactive - Devoxx 2015
3h à l'assaut d'une application réactive - Devoxx 2015
Publicis Sapient Engineering
 
Webhooks
WebhooksWebhooks
WebHooks in 10 Minutes
WebHooks in 10 MinutesWebHooks in 10 Minutes
WebHooks in 10 Minutes
Jeff Lindsay
 
Things I Learned From Having Users
Things I Learned From Having UsersThings I Learned From Having Users
Things I Learned From Having UsersDave Cross
 
Re invent 2018 - The Evolution of AircraftML
Re invent 2018  - The Evolution of AircraftMLRe invent 2018  - The Evolution of AircraftML
Re invent 2018 - The Evolution of AircraftML
jerryhargrove
 
Yan Cui - How to build observability into a serverless application - Codemoti...
Yan Cui - How to build observability into a serverless application - Codemoti...Yan Cui - How to build observability into a serverless application - Codemoti...
Yan Cui - How to build observability into a serverless application - Codemoti...
Codemotion
 
Monitoring using Sensu
Monitoring using SensuMonitoring using Sensu
Monitoring using Sensu
ripienaar
 
gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!
Alex Borysov
 
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
Alex Borysov
 
"gRPC vs REST: let the battle begin!" OSCON 2018 edition
"gRPC vs REST: let the battle begin!" OSCON 2018 edition"gRPC vs REST: let the battle begin!" OSCON 2018 edition
"gRPC vs REST: let the battle begin!" OSCON 2018 edition
Alex Borysov
 
"gRPC vs REST: let the battle begin!" DevoxxUK 2018 edition
"gRPC vs REST: let the battle begin!" DevoxxUK 2018 edition"gRPC vs REST: let the battle begin!" DevoxxUK 2018 edition
"gRPC vs REST: let the battle begin!" DevoxxUK 2018 edition
Alex Borysov
 
Connecting to the Pulse of the Planet with the Twitter Platform
Connecting to the Pulse of the Planet with the Twitter PlatformConnecting to the Pulse of the Planet with the Twitter Platform
Connecting to the Pulse of the Planet with the Twitter Platform
Andy Piper
 
gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!
Alex Borysov
 
How WebHooks Will Make Us All Programmers
How WebHooks Will Make Us All ProgrammersHow WebHooks Will Make Us All Programmers
How WebHooks Will Make Us All Programmers
Jeff Lindsay
 
Spacebrew Server Workshop @ ITP
Spacebrew Server Workshop @ ITPSpacebrew Server Workshop @ ITP
Spacebrew Server Workshop @ ITP
Julio Terra
 
"gRPC vs REST: let the battle begin!" GeeCON Krakow 2018 edition
"gRPC vs REST: let the battle begin!" GeeCON Krakow 2018 edition"gRPC vs REST: let the battle begin!" GeeCON Krakow 2018 edition
"gRPC vs REST: let the battle begin!" GeeCON Krakow 2018 edition
Alex Borysov
 
APIs That Make Things Happen
APIs That Make Things HappenAPIs That Make Things Happen
APIs That Make Things Happen
Jeff Lindsay
 
OSCON 2019 "Break me if you can: practical guide to building fault-tolerant s...
OSCON 2019 "Break me if you can: practical guide to building fault-tolerant s...OSCON 2019 "Break me if you can: practical guide to building fault-tolerant s...
OSCON 2019 "Break me if you can: practical guide to building fault-tolerant s...
Alex Borysov
 
"gRPC-Web: It’s All About Communication": Devoxx Ukraine 2019
"gRPC-Web:  It’s All About Communication": Devoxx Ukraine 2019"gRPC-Web:  It’s All About Communication": Devoxx Ukraine 2019
"gRPC-Web: It’s All About Communication": Devoxx Ukraine 2019
Alex Borysov
 
Cómo construir pipelines para streaming de datos en visualizaciones: Un ejemp...
Cómo construir pipelines para streaming de datos en visualizaciones: Un ejemp...Cómo construir pipelines para streaming de datos en visualizaciones: Un ejemp...
Cómo construir pipelines para streaming de datos en visualizaciones: Un ejemp...
Software Guru
 

What's hot (20)

3h à l'assaut d'une application réactive - Devoxx 2015
3h à l'assaut d'une application réactive - Devoxx 20153h à l'assaut d'une application réactive - Devoxx 2015
3h à l'assaut d'une application réactive - Devoxx 2015
 
Webhooks
WebhooksWebhooks
Webhooks
 
WebHooks in 10 Minutes
WebHooks in 10 MinutesWebHooks in 10 Minutes
WebHooks in 10 Minutes
 
Things I Learned From Having Users
Things I Learned From Having UsersThings I Learned From Having Users
Things I Learned From Having Users
 
Re invent 2018 - The Evolution of AircraftML
Re invent 2018  - The Evolution of AircraftMLRe invent 2018  - The Evolution of AircraftML
Re invent 2018 - The Evolution of AircraftML
 
Yan Cui - How to build observability into a serverless application - Codemoti...
Yan Cui - How to build observability into a serverless application - Codemoti...Yan Cui - How to build observability into a serverless application - Codemoti...
Yan Cui - How to build observability into a serverless application - Codemoti...
 
Monitoring using Sensu
Monitoring using SensuMonitoring using Sensu
Monitoring using Sensu
 
gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!
 
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition
 
"gRPC vs REST: let the battle begin!" OSCON 2018 edition
"gRPC vs REST: let the battle begin!" OSCON 2018 edition"gRPC vs REST: let the battle begin!" OSCON 2018 edition
"gRPC vs REST: let the battle begin!" OSCON 2018 edition
 
"gRPC vs REST: let the battle begin!" DevoxxUK 2018 edition
"gRPC vs REST: let the battle begin!" DevoxxUK 2018 edition"gRPC vs REST: let the battle begin!" DevoxxUK 2018 edition
"gRPC vs REST: let the battle begin!" DevoxxUK 2018 edition
 
Connecting to the Pulse of the Planet with the Twitter Platform
Connecting to the Pulse of the Planet with the Twitter PlatformConnecting to the Pulse of the Planet with the Twitter Platform
Connecting to the Pulse of the Planet with the Twitter Platform
 
gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!
 
How WebHooks Will Make Us All Programmers
How WebHooks Will Make Us All ProgrammersHow WebHooks Will Make Us All Programmers
How WebHooks Will Make Us All Programmers
 
Spacebrew Server Workshop @ ITP
Spacebrew Server Workshop @ ITPSpacebrew Server Workshop @ ITP
Spacebrew Server Workshop @ ITP
 
"gRPC vs REST: let the battle begin!" GeeCON Krakow 2018 edition
"gRPC vs REST: let the battle begin!" GeeCON Krakow 2018 edition"gRPC vs REST: let the battle begin!" GeeCON Krakow 2018 edition
"gRPC vs REST: let the battle begin!" GeeCON Krakow 2018 edition
 
APIs That Make Things Happen
APIs That Make Things HappenAPIs That Make Things Happen
APIs That Make Things Happen
 
OSCON 2019 "Break me if you can: practical guide to building fault-tolerant s...
OSCON 2019 "Break me if you can: practical guide to building fault-tolerant s...OSCON 2019 "Break me if you can: practical guide to building fault-tolerant s...
OSCON 2019 "Break me if you can: practical guide to building fault-tolerant s...
 
"gRPC-Web: It’s All About Communication": Devoxx Ukraine 2019
"gRPC-Web:  It’s All About Communication": Devoxx Ukraine 2019"gRPC-Web:  It’s All About Communication": Devoxx Ukraine 2019
"gRPC-Web: It’s All About Communication": Devoxx Ukraine 2019
 
Cómo construir pipelines para streaming de datos en visualizaciones: Un ejemp...
Cómo construir pipelines para streaming de datos en visualizaciones: Un ejemp...Cómo construir pipelines para streaming de datos en visualizaciones: Un ejemp...
Cómo construir pipelines para streaming de datos en visualizaciones: Un ejemp...
 

Similar to Building Serverless applications with Python

Origins of Serverless
Origins of ServerlessOrigins of Serverless
Origins of Serverless
Andrii Soldatenko
 
Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24
Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24
Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24
Kei IWASAKI
 
Building serverless-applications
Building serverless-applicationsBuilding serverless-applications
Building serverless-applications
Andrii Soldatenko
 
Apache StreamPipes – Flexible Industrial IoT Management
Apache StreamPipes – Flexible Industrial IoT ManagementApache StreamPipes – Flexible Industrial IoT Management
Apache StreamPipes – Flexible Industrial IoT Management
Apache StreamPipes
 
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
Microservices Application Tracing Standards and Simulators - Adrians at OSCONMicroservices Application Tracing Standards and Simulators - Adrians at OSCON
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
Adrian Cockcroft
 
Build a RESTful API with the Serverless Framework
Build a RESTful API with the Serverless FrameworkBuild a RESTful API with the Serverless Framework
Build a RESTful API with the Serverless Framework
masahitojp
 
Swift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Swift MicroservicesSwift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Swift Microservices
Chris Bailey
 
PyCon Canada 2015 - Is your python application secure
PyCon Canada 2015 - Is your python application securePyCon Canada 2015 - Is your python application secure
PyCon Canada 2015 - Is your python application secure
IMMUNIO
 
BigDataFest Building Modern Data Streaming Apps
BigDataFest  Building Modern Data Streaming AppsBigDataFest  Building Modern Data Streaming Apps
BigDataFest Building Modern Data Streaming Apps
ssuser73434e
 
Serverless, The Middy Way - Workshop
Serverless, The Middy Way - WorkshopServerless, The Middy Way - Workshop
Serverless, The Middy Way - Workshop
Luciano Mammino
 
Conf42 Python_ ML Enhanced Event Streaming Apps with Python Microservices
Conf42 Python_ ML Enhanced Event Streaming Apps with Python MicroservicesConf42 Python_ ML Enhanced Event Streaming Apps with Python Microservices
Conf42 Python_ ML Enhanced Event Streaming Apps with Python Microservices
Timothy Spann
 
Is your python application secure? - PyCon Canada - 2015-11-07
Is your python application secure? - PyCon Canada - 2015-11-07Is your python application secure? - PyCon Canada - 2015-11-07
Is your python application secure? - PyCon Canada - 2015-11-07
Frédéric Harper
 
2022 APIsecure_Securing APIs with Open Standards
2022 APIsecure_Securing APIs with Open Standards2022 APIsecure_Securing APIs with Open Standards
2022 APIsecure_Securing APIs with Open Standards
APIsecure_ Official
 
AppSec EU 2009 - HTTP Parameter Pollution by Luca Carettoni and Stefano di P...
AppSec EU 2009 - HTTP Parameter Pollution by Luca Carettoni and  Stefano di P...AppSec EU 2009 - HTTP Parameter Pollution by Luca Carettoni and  Stefano di P...
AppSec EU 2009 - HTTP Parameter Pollution by Luca Carettoni and Stefano di P...
Magno Logan
 
API Documentation Workshop tcworld India 2015
API Documentation Workshop tcworld India 2015API Documentation Workshop tcworld India 2015
API Documentation Workshop tcworld India 2015
Tom Johnson
 
Distributing UI Libraries: in a post Web-Component world
Distributing UI Libraries: in a post Web-Component worldDistributing UI Libraries: in a post Web-Component world
Distributing UI Libraries: in a post Web-Component world
Rachael L Moore
 
API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIs
Tom Johnson
 
What's Rio 〜Standalone〜
What's Rio 〜Standalone〜What's Rio 〜Standalone〜
What's Rio 〜Standalone〜
cyberblack28 Ichikawa
 
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
 
All You Need to Know to Deploy Applications on Kubernetes
All You Need to Know to Deploy Applications on KubernetesAll You Need to Know to Deploy Applications on Kubernetes
All You Need to Know to Deploy Applications on Kubernetes
VMware Tanzu
 

Similar to Building Serverless applications with Python (20)

Origins of Serverless
Origins of ServerlessOrigins of Serverless
Origins of Serverless
 
Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24
Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24
Collaboration hack with slackbot - PyCon HK 2018 - 2018.11.24
 
Building serverless-applications
Building serverless-applicationsBuilding serverless-applications
Building serverless-applications
 
Apache StreamPipes – Flexible Industrial IoT Management
Apache StreamPipes – Flexible Industrial IoT ManagementApache StreamPipes – Flexible Industrial IoT Management
Apache StreamPipes – Flexible Industrial IoT Management
 
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
Microservices Application Tracing Standards and Simulators - Adrians at OSCONMicroservices Application Tracing Standards and Simulators - Adrians at OSCON
Microservices Application Tracing Standards and Simulators - Adrians at OSCON
 
Build a RESTful API with the Serverless Framework
Build a RESTful API with the Serverless FrameworkBuild a RESTful API with the Serverless Framework
Build a RESTful API with the Serverless Framework
 
Swift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Swift MicroservicesSwift Cloud Workshop - Swift Microservices
Swift Cloud Workshop - Swift Microservices
 
PyCon Canada 2015 - Is your python application secure
PyCon Canada 2015 - Is your python application securePyCon Canada 2015 - Is your python application secure
PyCon Canada 2015 - Is your python application secure
 
BigDataFest Building Modern Data Streaming Apps
BigDataFest  Building Modern Data Streaming AppsBigDataFest  Building Modern Data Streaming Apps
BigDataFest Building Modern Data Streaming Apps
 
Serverless, The Middy Way - Workshop
Serverless, The Middy Way - WorkshopServerless, The Middy Way - Workshop
Serverless, The Middy Way - Workshop
 
Conf42 Python_ ML Enhanced Event Streaming Apps with Python Microservices
Conf42 Python_ ML Enhanced Event Streaming Apps with Python MicroservicesConf42 Python_ ML Enhanced Event Streaming Apps with Python Microservices
Conf42 Python_ ML Enhanced Event Streaming Apps with Python Microservices
 
Is your python application secure? - PyCon Canada - 2015-11-07
Is your python application secure? - PyCon Canada - 2015-11-07Is your python application secure? - PyCon Canada - 2015-11-07
Is your python application secure? - PyCon Canada - 2015-11-07
 
2022 APIsecure_Securing APIs with Open Standards
2022 APIsecure_Securing APIs with Open Standards2022 APIsecure_Securing APIs with Open Standards
2022 APIsecure_Securing APIs with Open Standards
 
AppSec EU 2009 - HTTP Parameter Pollution by Luca Carettoni and Stefano di P...
AppSec EU 2009 - HTTP Parameter Pollution by Luca Carettoni and  Stefano di P...AppSec EU 2009 - HTTP Parameter Pollution by Luca Carettoni and  Stefano di P...
AppSec EU 2009 - HTTP Parameter Pollution by Luca Carettoni and Stefano di P...
 
API Documentation Workshop tcworld India 2015
API Documentation Workshop tcworld India 2015API Documentation Workshop tcworld India 2015
API Documentation Workshop tcworld India 2015
 
Distributing UI Libraries: in a post Web-Component world
Distributing UI Libraries: in a post Web-Component worldDistributing UI Libraries: in a post Web-Component world
Distributing UI Libraries: in a post Web-Component world
 
API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIs
 
What's Rio 〜Standalone〜
What's Rio 〜Standalone〜What's Rio 〜Standalone〜
What's Rio 〜Standalone〜
 
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)
 
All You Need to Know to Deploy Applications on Kubernetes
All You Need to Know to Deploy Applications on KubernetesAll You Need to Know to Deploy Applications on Kubernetes
All You Need to Know to Deploy Applications on Kubernetes
 

More from Andrii Soldatenko

Debugging concurrency programs in go
Debugging concurrency programs in goDebugging concurrency programs in go
Debugging concurrency programs in go
Andrii 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 go
Andrii Soldatenko
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
Andrii 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 Python
Andrii 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
 
Practical continuous quality gates for development process
Practical continuous quality gates for development processPractical continuous quality gates for development process
Practical continuous quality gates for development process
Andrii Soldatenko
 
Kyiv.py #16 october 2015
Kyiv.py #16 october 2015Kyiv.py #16 october 2015
Kyiv.py #16 october 2015
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 Soldatenko
Andrii Soldatenko
 
PyCon Ukraine 2014
PyCon Ukraine 2014PyCon Ukraine 2014
PyCon Ukraine 2014
Andrii Soldatenko
 
SeleniumCamp 2015 Andrii Soldatenko
SeleniumCamp 2015 Andrii SoldatenkoSeleniumCamp 2015 Andrii Soldatenko
SeleniumCamp 2015 Andrii Soldatenko
Andrii Soldatenko
 

More from Andrii Soldatenko (11)

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?
 
Practical continuous quality gates for development process
Practical continuous quality gates for development processPractical continuous quality gates for development process
Practical continuous quality gates for development process
 
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
 
PyCon Ukraine 2014
PyCon Ukraine 2014PyCon Ukraine 2014
PyCon Ukraine 2014
 
SeleniumCamp 2015 Andrii Soldatenko
SeleniumCamp 2015 Andrii SoldatenkoSeleniumCamp 2015 Andrii Soldatenko
SeleniumCamp 2015 Andrii Soldatenko
 

Recently uploaded

GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 

Recently uploaded (20)

GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 

Building Serverless applications with Python

  • 1. Building Serverless applications with Python3 Andrii Soldatenko 12 June 2017 @a_soldatenko
  • 2. Andrii Soldatenko • Senior Python Developer at Toptal • Speaker at many PyCons and open source contributor • blogger at https://asoldatenko.com @a_soldatenko cat /etc/passwd
  • 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 announced AWS Lambda https://techcrunch.com/2015/11/24/aws-lamda-makes- serverless-applications-a-reality/
  • 14. How Lambda works - function name; - memory size - timeout; - role; @a_soldatenko
  • 15. Your first λ function def lambda_handler(event, context): message = 'Hello {}!'.format(event['name']) return {'message': message} @a_soldatenko
  • 16. 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
  • 17. Invoke λ function aws lambda invoke --function-name HelloPython --payload '{"name":"PyCon Italy"}' output.txt cat output.txt {"message": "Hello PyCon Italy!"}% @a_soldatenko
  • 18. 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
  • 20. 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
  • 21. ...
 ...
 ...
 @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
  • 22. 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
  • 23. 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
  • 24. Chalice under the hood @a_soldatenko - botocore; - typing;
  • 25. Chalice under the hood @a_soldatenko
  • 29. AWS Lambda without any costs @a_soldatenko - The first 400,000 seconds of execution time with 1 GB of memory
  • 30. What if you want to run your Django app? @a_soldatenko
  • 33. @a_soldatenko And again what do you mean “serveless”?
  • 34. @a_soldatenko ➜ pip install zappa ➜ zappa init ███████╗ █████╗ ██████╗ ██████╗ █████╗ ╚══███╔╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗ ███╔╝ ███████║██████╔╝██████╔╝███████║ ███╔╝ ██╔══██║██╔═══╝ ██╔═══╝ ██╔══██║ ███████╗██║ ██║██║ ██║ ██║ ██║ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ Welcome to Zappa! ... ➜ zappa deploy https://github.com/Miserlou/Zappa
  • 35. @a_soldatenkohttps://github.com/Miserlou/Zappa - deploy; - tailing logs; - run django manage.py
 … ███████╗ █████╗ ██████╗ ██████╗ █████╗ ╚══███╔╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗ ███╔╝ ███████║██████╔╝██████╔╝███████║ ███╔╝ ██╔══██║██╔═══╝ ██╔═══╝ ██╔══██║ ███████╗██║ ██║██║ ██║ ██║ ██║ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝
  • 38. Python 2.7 will retire in... @a_soldatenkohttps://pythonclock.org/
  • 39. 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
  • 40. 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)
  • 41. 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!!:
  • 42. Run python 3 from python 2 @a_soldatenko
  • 43. 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
  • 44. 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)
  • 45. 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
  • 46. Thanks Lyndon Swan for ideas about hacking python 3 @a_soldatenko
  • 47. 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
  • 48. @a_soldatenko From Apr 18, 2017 AWS Lambda Supports Python 3.6
  • 50. Using binaries with your function
  • 51. yum update -y yum install -y git cmake gcc-c++ gcc python- devel chrpath mkdir -p lambda-package/cv2 build/numpy ... pip install opencv-python -t . ... # Copy template function and zip package cp template.py lambda-package/lambda_function.py cd lambda-package zip -r ../lambda-package.zip * Prepare wheels
  • 52. import cv2 def lambda_handler(event, context): print(“OpenCV installed version:", cv2.__version__) return "It works!" lambda function
  • 53. START RequestId: 19e6a8f9-4eea-11e7-a662-299188c47179 Version: $LATEST OpenCV installed version: 3.2.0 END RequestId: 19e6a8f9-4eea-11e7-a662-299188c47179 REPORT RequestId: 19e6a8f9-4eea-11e7- a662-299188c47179 Duration: 0.46 ms Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 35 MB
  • 54.
  • 55. import importlib import sys # Import your lambda python module mod = importlib.import_module(sys.argv[1]) function_handler = sys.argv[2] lambda_function = getattr(mod, function_handler ) event = {'name': 'Andrii'} context = {'conference_name': 'PyCon Israel'} try: data = function_handler(event, context) print(data) except Exception as error: print(error) How to run lambda locally
  • 56. $ python local_lambda.py lambda_function lambda_handler {'message': 'Hello Andrii!'} How to run lambda locally
  • 57. What about websockets? A: No, API Gateway doesn’t support https://forums.aws.amazon.com/thread.jspa?threadID=205761
  • 58. AWS IoT Now Supports WebSockets http://stesie.github.io/2016/04/aws-iot-pubsub