ZAPPA

Do that Python thing - without the servers!

Ricardo Moreno

  • Backend developer at Yokee Musicâ„¢
  • Python enthusiast for more than 5 years
  • github/ricardinho

Example problem

Add a watermark to a picture that was uploaded in your app

Zappa

Created by Rich Jones (github/miserlou)

Zappa

Serverless Python Web Services - Powered by AWS Lambda and API Gateway

Zappa

  • Serverless
  • Python Web Services
  • AWS Lambda
  • API Gateway

Zappa

  • Serverless
  • Python Web Services
  • AWS Lambda
  • API Gateway

Python

  • We love python
  • WSGI* for web apps (pep 333)

*Web Server Gateway Interface

Zappa

  • Serverless
  • Python Web Services
  • AWS Lambda
  • API Gateway

Serverless

The name that cloud providers give to Microservices

Wait...

The name that cloud providers give to Microservices

Microservices

  • Small software components
  • Invoked by Triggers

Small software components

Think Functions!

Triggers

  • Web requests
  • Queues
  • Application events (think DB triggers)
  • Scheduled runs (CRON)

Serverless

Cloud Provider Service Name
AWS Lambda
Microsoft Azure Functions
Google Cloud Functions

Example - Add a watermark to a picture

Zappa

  • Serverless
  • Python Web Services
  • AWS Lambda
  • API Gateway

AWS Lambda

  • Nodejs
  • JVM
  • Python 2.7
  • Python 3.6!!!

AWS Lambda - Function

Handler function

def my_handler(event, context):
    return "response!"

AWS Lambda - Triggers

  • SNS
  • DynamoDB
  • S3
  • CloudWatch Events (Including scheduled events)
  • API Gateway

Zappa

  • Serverless
  • Python Web Services
  • AWS Lambda
  • API Gateway

API Gateway

  • API Versioning
  • Authentication
  • Throttling
  • Multiple Backends

API Gateway

Converts HTML into Lambda event/context objects

AWS Lambda - Function

Handler function

def my_handler(event, context):
    return "response!"

Python

PEP 333 (WSGI) !!!

def wsgi_function(environ, start_response):
    return "response!"

ZAPPA

Converts lambda event/context into WSGI

ZAPPA

Supports all python WSGI frameworks

  • Django
  • Flask
  • Pyramid
  • And More...

ZAPPA

Can create all the AWS permissions/roles/buckets for you

zappa init

Understand what this step does

ZAPPA

Manage your deployments

zappa deploy
zappa update

ZAPPA

Understand what is going on inside your app

zappa status
zappa tail

ZAPPA

Configure Events

"events": [
            {   // Recurring events
                "function": "your_module.your_recurring_function", // The function to execute
                "expression": "rate(1 minute)" // When to execute it (in cron or rate format)
            },
            {   // AWS Reactive events
                "function": "your_module.your_reactive_function", // The function to execute
                "event_source": {
                    "arn":  "arn:aws:s3:::my-bucket", // The ARN of this event source
                    "events": [
                        "s3:ObjectCreated:*" // The specific event to execute in response to.
                    ]
                }
            }
        ]

ZAPPA - other goodies

Environment variables in zappa config, S3 or KMS

Certificate management

Django management commands

Zappa - good takeaways

Leverages writing python apps on AWS Lambda

AWS is cheap - specially for small apps

Zappa - bad takeaways

Default options are permissive security wise

What was missing?

Serverless = Stateless

you still need to store your data somewhere

Thank You!