SlideShare una empresa de Scribd logo
1 de 13
Django and AWS
Lambda
Malcolm Box
malcolm.box@gmail.com
Sometimes: @malcolmbox
Very occasionally: https://attentionshard.wordpress.com
About me
• Working with Django since 2009 (Django 1.1)
• CTO of Tellybug where we made apps for TV
shows and a very scalable platform using Django
& AWS
• Recently started building a new project using
serverless
• Consulting CTO working with startups
“AWS Lambda is a compute service that
lets you run code without provisioning or
managing servers”
Data Centre
Server
Linux
nginx
gunicorn
Django
def view(request):
return
render(request,
"demo.html")
*Not to scale
https://github.com/Miserlou/Zappa
Demo!
• You will need:
• AWS Credentials
• A python virtualenv
• Instructions and example code:
https://github.com/mbox/djugl-demo
Other Zappa goodness
$ zappa tail
Calling tail for stage demo..
[1497350426182] [DEBUG] 2017-06-13T10:40:26.182Z b55a7b0b-5024-11e7-8e46-47e2239fb3ce Zappa Event: {u'body': None, u'resource':
u'/', u'requestContext': {u'resourceId': u'gm6q48zq93', u'apiId': u'lkvzkzlzd6', u'resourcePath': u'/', u'httpMethod': u'GET', u'requestId':
u'b54d0e51-5024-11e7-b059-6324c1a6f402', u'path': u'/demo', u'accountId': u'956653133436', u'identity': {u'apiKey': u'', u'userArn': None,
u'cognitoAuthenticationType': None, u'accessKey': None, u'caller': None, u'userAgent': u'python-requests/2.17.3', u'user': None,
u'cognitoIdentityPoolId': None, u'cognitoIdentityId': None, u'cognitoAuthenticationProvider': None, u'sourceIp': u'82.3.163.138', u'accountId':
None}, u'stage': u'demo'}, u'queryStringParameters': None, u'httpMethod': u'GET', u'pathParameters': None, u'headers': {u'Via': u'1.1
2e578cf3c3154a7d5d4f253d74c2b940.cloudfront.net (CloudFront)', u'Accept-Encoding': u'gzip, deflate', u'CloudFront-Is-SmartTV-Viewer':
u'false', u'CloudFront-Forwarded-Proto': u'https', u'X-Forwarded-For': u'82.3.163.138, 54.182.244.97', u'CloudFront-Viewer-Country': u'GB',
u'Accept': u'*/*', u'User-Agent': u'python-requests/2.17.3', u'X-Amzn-Trace-Id': u'Root=1-593fc118-7e2199041b9cd95f3abfe753', u'Host':
u'lkvzkzlzd6.execute-api.eu-west-1.amazonaws.com', u'X-Forwarded-Proto': u'https', u'X-Amz-Cf-Id': u'1Cn8Ygt_ftJmfKnGiNqCTOO2SNT-
gcNigAY0DXARyP2O500N8oEZGQ==', u'CloudFront-Is-Tablet-Viewer': u'false', u'X-Forwarded-Port': u'443', u'CloudFront-Is-Mobile-Viewer':
u'false', u'CloudFront-Is-Desktop-Viewer': u'true'}, u'stageVariables': None, u'path': u'/', u'isBase64Encoded': False}
[1497350426184] Invalid HTTP_HOST header: 'lkvzkzlzd6.execute-api.eu-west-1.amazonaws.com'. You may need to add u'lkvzkzlzd6.execute-
api.eu-west-1.amazonaws.com' to ALLOWED_HOSTS.
[1497350426184] [ERROR] 2017-06-13T10:40:26.183Z b55a7b0b-5024-11e7-8e46-47e2239fb3ce Invalid HTTP_HOST header:
'lkvzkzlzd6.execute-api.eu-west-1.amazonaws.com'. You may need to add u'lkvzkzlzd6.execute-api.eu-west-1.amazonaws.com' to
ALLOWED_HOSTS.
[1497350426341] [INFO] 2017-06-13T10:40:26.341Z b55a7b0b-5024-11e7-8e46-47e2239fb3ce 82.3.163.138 - - [13/Jun/2017:10:40:26 +0000]
"GET / HTTP/1.1" 400 37968 "" "python-requests/2.17.3" 0/158.477
zappa manage
$ zappa manage demo migrate
START RequestId: da3e8e84-5039-11e7-9c38-2913a464f8e0 Version: $LATEST
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
END RequestId: da3e8e84-5039-11e7-9c38-2913a464f8e0
REPORT RequestId: da3e8e84-5039-11e7-9c38-2913a464f8e0Duration: 386.42 msBilled Duration: 400 ms
Memory Size: 512 MB Max Memory Used: 52 MB
zappa schedule
Asynchronous Task
Execution
from flask import Flask
from zappa.async import task
app = Flask(__name__)
@task
def make_pie():
""" This takes a long time! """
ingredients = get_ingredients()
pie = bake(ingredients)
deliver(pie)
@app.route('/api/order/pie')
def order_pie():
""" This returns immediately! """
make_pie()
return "Your pie is being made!"
Going further
• Database - can use RDS, Dynamo, Redshift etc
• GeoDjango & binary libraries - issues if they get
too big
• Python 3 - now supported
• Static files - use Whitenoise
http://whitenoise.evans.io
Thank you!

Más contenido relacionado

La actualidad más candente

Speeding up Page Load Times by Using the Starling Queue Server
Speeding up Page Load Times by Using the Starling Queue ServerSpeeding up Page Load Times by Using the Starling Queue Server
Speeding up Page Load Times by Using the Starling Queue Server
Erik Osterman
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
Rick Copeland
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
clkao
 

La actualidad más candente (19)

DevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and WebminDevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and Webmin
 
Coolblue - Behind the Scenes Continuous Integration & Deployment
Coolblue - Behind the Scenes Continuous Integration & DeploymentCoolblue - Behind the Scenes Continuous Integration & Deployment
Coolblue - Behind the Scenes Continuous Integration & Deployment
 
Put kajakken på hylden - og få sexede windows services
Put kajakken på hylden - og få sexede windows servicesPut kajakken på hylden - og få sexede windows services
Put kajakken på hylden - og få sexede windows services
 
Getting started with node.js
Getting started with node.jsGetting started with node.js
Getting started with node.js
 
Bundler
BundlerBundler
Bundler
 
Write php deploy everywhere
Write php deploy everywhereWrite php deploy everywhere
Write php deploy everywhere
 
Speeding up Page Load Times by Using the Starling Queue Server
Speeding up Page Load Times by Using the Starling Queue ServerSpeeding up Page Load Times by Using the Starling Queue Server
Speeding up Page Load Times by Using the Starling Queue Server
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
 
Html5, css3, canvas, svg and webgl
Html5, css3, canvas, svg and webglHtml5, css3, canvas, svg and webgl
Html5, css3, canvas, svg and webgl
 
Designing net-aws-glacier
Designing net-aws-glacierDesigning net-aws-glacier
Designing net-aws-glacier
 
Start using vagrant now!
Start using vagrant now!Start using vagrant now!
Start using vagrant now!
 
Capistrano - automate all the things
Capistrano - automate all the thingsCapistrano - automate all the things
Capistrano - automate all the things
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
Running azure function locally
Running azure function locallyRunning azure function locally
Running azure function locally
 
Capistrano
CapistranoCapistrano
Capistrano
 
Virtual Infrastructure
Virtual InfrastructureVirtual Infrastructure
Virtual Infrastructure
 
PyCon Russia 2014 - Auto Scale in the Cloud
PyCon Russia 2014 - Auto Scale in the CloudPyCon Russia 2014 - Auto Scale in the Cloud
PyCon Russia 2014 - Auto Scale in the Cloud
 
Background Jobs with Resque
Background Jobs with ResqueBackground Jobs with Resque
Background Jobs with Resque
 
asyncio community, one year later
asyncio community, one year laterasyncio community, one year later
asyncio community, one year later
 

Similar a DJUGL - Django and AWS Lambda

ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale
Subbu Allamaraju
 
MesosCon - Be a microservices hero
MesosCon - Be a microservices heroMesosCon - Be a microservices hero
MesosCon - Be a microservices hero
Dragos Dascalita Haut
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 

Similar a DJUGL - Django and AWS Lambda (20)

Pyrax talk
Pyrax talkPyrax talk
Pyrax talk
 
Cooking Up Drama
Cooking Up DramaCooking Up Drama
Cooking Up Drama
 
Cooking Up Drama - ChefConf 2015
Cooking Up Drama - ChefConf 2015 Cooking Up Drama - ChefConf 2015
Cooking Up Drama - ChefConf 2015
 
PSGI/Plack OSDC.TW
PSGI/Plack OSDC.TWPSGI/Plack OSDC.TW
PSGI/Plack OSDC.TW
 
Easy Cloud Native Transformation using HashiCorp Nomad
Easy Cloud Native Transformation using HashiCorp NomadEasy Cloud Native Transformation using HashiCorp Nomad
Easy Cloud Native Transformation using HashiCorp Nomad
 
ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale
 
NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!
 
Advanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutesAdvanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutes
 
how to use openstack api
how to use openstack apihow to use openstack api
how to use openstack api
 
About Clack
About ClackAbout Clack
About Clack
 
MesosCon - Be a microservices hero
MesosCon - Be a microservices heroMesosCon - Be a microservices hero
MesosCon - Be a microservices hero
 
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Mangling
Mangling Mangling
Mangling
 
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
Ondřej Šika: Docker, Traefik a CI - Mějte nasazené všeny větve na kterých pra...
 
Future of Serverless
Future of ServerlessFuture of Serverless
Future of Serverless
 
Try to use chromeless on AWS Lambda
Try to use chromeless on AWS LambdaTry to use chromeless on AWS Lambda
Try to use chromeless on AWS Lambda
 
AWS DevOps - Terraform, Docker, HashiCorp Vault
AWS DevOps - Terraform, Docker, HashiCorp VaultAWS DevOps - Terraform, Docker, HashiCorp Vault
AWS DevOps - Terraform, Docker, HashiCorp Vault
 
Lights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFeverLights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFever
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

DJUGL - Django and AWS Lambda

  • 1. Django and AWS Lambda Malcolm Box malcolm.box@gmail.com Sometimes: @malcolmbox Very occasionally: https://attentionshard.wordpress.com
  • 2. About me • Working with Django since 2009 (Django 1.1) • CTO of Tellybug where we made apps for TV shows and a very scalable platform using Django & AWS • Recently started building a new project using serverless • Consulting CTO working with startups
  • 3. “AWS Lambda is a compute service that lets you run code without provisioning or managing servers”
  • 4.
  • 7. Demo! • You will need: • AWS Credentials • A python virtualenv • Instructions and example code: https://github.com/mbox/djugl-demo
  • 8. Other Zappa goodness $ zappa tail Calling tail for stage demo.. [1497350426182] [DEBUG] 2017-06-13T10:40:26.182Z b55a7b0b-5024-11e7-8e46-47e2239fb3ce Zappa Event: {u'body': None, u'resource': u'/', u'requestContext': {u'resourceId': u'gm6q48zq93', u'apiId': u'lkvzkzlzd6', u'resourcePath': u'/', u'httpMethod': u'GET', u'requestId': u'b54d0e51-5024-11e7-b059-6324c1a6f402', u'path': u'/demo', u'accountId': u'956653133436', u'identity': {u'apiKey': u'', u'userArn': None, u'cognitoAuthenticationType': None, u'accessKey': None, u'caller': None, u'userAgent': u'python-requests/2.17.3', u'user': None, u'cognitoIdentityPoolId': None, u'cognitoIdentityId': None, u'cognitoAuthenticationProvider': None, u'sourceIp': u'82.3.163.138', u'accountId': None}, u'stage': u'demo'}, u'queryStringParameters': None, u'httpMethod': u'GET', u'pathParameters': None, u'headers': {u'Via': u'1.1 2e578cf3c3154a7d5d4f253d74c2b940.cloudfront.net (CloudFront)', u'Accept-Encoding': u'gzip, deflate', u'CloudFront-Is-SmartTV-Viewer': u'false', u'CloudFront-Forwarded-Proto': u'https', u'X-Forwarded-For': u'82.3.163.138, 54.182.244.97', u'CloudFront-Viewer-Country': u'GB', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.17.3', u'X-Amzn-Trace-Id': u'Root=1-593fc118-7e2199041b9cd95f3abfe753', u'Host': u'lkvzkzlzd6.execute-api.eu-west-1.amazonaws.com', u'X-Forwarded-Proto': u'https', u'X-Amz-Cf-Id': u'1Cn8Ygt_ftJmfKnGiNqCTOO2SNT- gcNigAY0DXARyP2O500N8oEZGQ==', u'CloudFront-Is-Tablet-Viewer': u'false', u'X-Forwarded-Port': u'443', u'CloudFront-Is-Mobile-Viewer': u'false', u'CloudFront-Is-Desktop-Viewer': u'true'}, u'stageVariables': None, u'path': u'/', u'isBase64Encoded': False} [1497350426184] Invalid HTTP_HOST header: 'lkvzkzlzd6.execute-api.eu-west-1.amazonaws.com'. You may need to add u'lkvzkzlzd6.execute- api.eu-west-1.amazonaws.com' to ALLOWED_HOSTS. [1497350426184] [ERROR] 2017-06-13T10:40:26.183Z b55a7b0b-5024-11e7-8e46-47e2239fb3ce Invalid HTTP_HOST header: 'lkvzkzlzd6.execute-api.eu-west-1.amazonaws.com'. You may need to add u'lkvzkzlzd6.execute-api.eu-west-1.amazonaws.com' to ALLOWED_HOSTS. [1497350426341] [INFO] 2017-06-13T10:40:26.341Z b55a7b0b-5024-11e7-8e46-47e2239fb3ce 82.3.163.138 - - [13/Jun/2017:10:40:26 +0000] "GET / HTTP/1.1" 400 37968 "" "python-requests/2.17.3" 0/158.477
  • 9. zappa manage $ zappa manage demo migrate START RequestId: da3e8e84-5039-11e7-9c38-2913a464f8e0 Version: $LATEST Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: No migrations to apply. END RequestId: da3e8e84-5039-11e7-9c38-2913a464f8e0 REPORT RequestId: da3e8e84-5039-11e7-9c38-2913a464f8e0Duration: 386.42 msBilled Duration: 400 ms Memory Size: 512 MB Max Memory Used: 52 MB
  • 11. Asynchronous Task Execution from flask import Flask from zappa.async import task app = Flask(__name__) @task def make_pie(): """ This takes a long time! """ ingredients = get_ingredients() pie = bake(ingredients) deliver(pie) @app.route('/api/order/pie') def order_pie(): """ This returns immediately! """ make_pie() return "Your pie is being made!"
  • 12. Going further • Database - can use RDS, Dynamo, Redshift etc • GeoDjango & binary libraries - issues if they get too big • Python 3 - now supported • Static files - use Whitenoise http://whitenoise.evans.io

Notas del editor

  1. Serverless is the architectural pattern Google Cloud Functions and AWS Lambda are (two) examples Runs Python, Java or Javascript code in response to events No servers...
  2. Not permanent Not managed by you Not paid for unless *doing* something for you
  3. “Hey, I wanna serve a web page” 1990s - build a data centre 2000s - Hosting 2006 - AWS 2013 - Docker 2014 - AWS Lambda
  4. Serverless Python Web Services Django or Flask on Lambda
  5. Scheduled tasks running as AWS lambda functions
  6. VPC wrangling for RDS + API Gateway - you need two VPCs with Internet gateways. This is not well documented!