Slide 1

Slide 1 text

Introduciendo Serverless en Proyectos Python Carlos Hernando @chernando

Slide 2

Slide 2 text

Serverless Hype! https://trends.google.com/trends/explore?date=2014-01-01%202017-08-27&q=serverless

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Serverless

Slide 6

Slide 6 text

Saas / BaaS

Slide 7

Slide 7 text

Está usted aquí Nuestra Aplicación

Slide 8

Slide 8 text

def handler(event, context): # PONGA SU CÓDIGO AQUÍ return AWS Lambda

Slide 9

Slide 9 text

Serverless

Slide 10

Slide 10 text

https://aws.amazon.com/serverless/

Slide 11

Slide 11 text

Arquitectura Serverless https://medium.com/cloud-academy-inc/serverless-beyond-functions-cd81ee4c6b8d

Slide 12

Slide 12 text

Escenarios

Slide 13

Slide 13 text

Scripts de “mantenimiento”

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

AWS Lambda

Slide 16

Slide 16 text

def handler(event, context): # PONGA SU CÓDIGO AQUÍ return

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

AWS Lambda Desarrolladores Credenciales Base de datos Servidores

Slide 19

Slide 19 text

Empaquetar $ cd venv/lib/python3.6/site-packages/ $ zip -r9 ../../../../deploy.zip * $ cd - $ zip -g deploy.zip *.py

Slide 20

Slide 20 text

Crear Lambda $ aws lambda create-function \ --region eu-west-1 \ --function-name SimpleScript \ --zip-file fileb://deploy.zip \ --role arn:aws:iam::XXX:role/MyLambdaRole \ --vpc-config SubnetIds=XXX,SecurityGroupIds=XXX \ --handler handler.handler \ --runtime python3.6 \ --profile personal \ --timeout 10 \ --memory-size 512

Slide 21

Slide 21 text

Actualizar Lambda $ aws lambda update-function-code \ --region eu-west-1 \ --function-name SimpleScript \ --zip-file fileb://deploy.zip \ --profile personal

Slide 22

Slide 22 text

Aprendizajes

Slide 23

Slide 23 text

Tareas periódicas

Slide 24

Slide 24 text

# Crontab 30 08 10 06 * /root/full-backup 00 11,16 * * * /root/incremental-backup 00 09-18 * * * /root/check-db-status 00 09-18 * * 1-5 /root/send-updates */10 * * * * /root/consolidate-reports @yearly /root/annual-maintenance @monthly /root/steal-money

Slide 25

Slide 25 text

Celery workers Celery Beat

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Celery Beat Celery workers

Slide 28

Slide 28 text

AWS Lambda Cloudwatch Events Celery workers

Slide 29

Slide 29 text

def handler(event, context): # PONGA SU CÓDIGO AQUÍ return

Slide 30

Slide 30 text

>>> from tasks import add >>> add.delay(4, 4)

Slide 31

Slide 31 text

>>> from celery import Celery >>> app = Celery(broker=broker) >>> app.send_task('tasks.add', args=[4,4])

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

https://serverless.com

Slide 34

Slide 34 text

functions: celeryless: handler: celeryless.handler events: - schedule: rate: rate(10 minutes) input: task: tasks.add args: [4, 4]

Slide 35

Slide 35 text

Aprendizajes

Slide 36

Slide 36 text

APIs a pequeña escala

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

API Gateway AWS Lambda

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

SAM: Serverless Application Model https://github.com/awslabs/serverless-application-model

Slide 41

Slide 41 text

https://github.com/aws/chalice

Slide 42

Slide 42 text

from flask import Flask app = Flask(__name__) @app.route("/") def index(): return "Hello World!"

Slide 43

Slide 43 text

from chalice import Chalice app = Chalice(app_name="helloworld") @app.route("/") def index(): return {"hello": "world"}

Slide 44

Slide 44 text

Aprendizajes

Slide 45

Slide 45 text

Eventos encadenados

Slide 46

Slide 46 text

Serverless Image resizing (AWS Lambda and AWS s3) http://blog.kaliloudiaby.com/index.php/serverless-image-resizing-aws-lambda-and-aws-s3/

Slide 47

Slide 47 text

De $0,20 a $834

Slide 48

Slide 48 text

14 horas $425 25.000.000 GB/s (290 días) 37.000.000 Invocaciones AWS Lambda

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Serverless Scripts Periódicos API HTTP

Slide 51

Slide 51 text

https://www.wdl.org/en/item/576/

Slide 52

Slide 52 text

Documentación de la charla: https://bit.ly/pymad0917 Carlos Hernando @chernando

Slide 53

Slide 53 text

•Photo by Chris Lawton on Unsplash •Photo by Maarten van den Heuvel on Unsplash •Photo by Markus Spiske on Unsplash •Photo by Teresa Kluge on Unsplash •Photo by Dan Paul on Unsplash •Photo by Mike Alonzo on Unsplash Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) https://creativecommons.org/licenses/by-sa/4.0/ Imágenes cortesía de: