@jmortegac europython 2018 josé manuel ortega · microservices and serverless in python projects...

Post on 21-May-2020

16 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Microservices and Serverless in Python projects

José Manuel OrtegaEuropython 2018

@jmortegac

v 0.5

Agenda

•Microservices in python• Introducing Serverless and Function as a Service•Python frameworks for AWS•AWS Lambda functions with zappa and chalice•Deploy AWS lambda functions from aws console

2Microservices and Serverless in Python projects

Microservices vs Serverless

3Microservices and Serverless in Python projects

Microservices

4Microservices and Serverless in Python projects

Asynchronous calls with asyncio and aiohttp

5Microservices and Serverless in Python projects

REST API Development

6Microservices and Serverless in Python projects

Performance

7Microservices and Serverless in Python projects

8% less memory6% faster response times

Microservices with graphql

8Microservices and Serverless in Python projects

9Microservices and Serverless in Python projects

10Microservices and Serverless in Python projects

11Microservices and Serverless in Python projects

12Microservices and Serverless in Python projects

13Microservices and Serverless in Python projects

SERVER

14Microservices and Serverless in Python projects

CLIENT

Microservices benefits

•Separation of concerns•Services are decoupled from each other•Managing smaller projects•More scaling and deployment options

15Microservices and Serverless in Python projects

16Microservices and Serverless in Python projects

Serverless

Serverless architecture

•FaaS - Function as a Service•Fully managed computing

• Provisioning• Scalability• Monitoring• Logging

•Deploy your code•Pay only for actual usage

17Microservices and Serverless in Python projects

Serverless architecture

18Microservices and Serverless in Python projects

Serverless uses cases➢ REST API

• Stateless services and microservices• Suitable for Chat bots

➢ Events• File processing (S3 event) & Data ingestion• Data/Stream processing• Incidents handling (CloudWatch event log)• IoT

➢ Scheduled tasks• Monitoring, load testing• Periodical jobs

19Microservices and Serverless in Python projects

20Microservices and Serverless in Python projects

Serverless benefits

•No server management•Automatic scaling and load balancing•Lower infrastructure costs•Flexibility and high availability• Infrastructure managed by service provider

21Microservices and Serverless in Python projects

Serverless drawbacks

• The tools around the deployment automation of serverless functions are still in development.

•There is no control over containers when the execution environments are created or destroyed

•Debugging, Deploying and monitoring

22Microservices and Serverless in Python projects

Cloud providers

•AWS•Microsoft Azure•Cloud platform•OpenWhisk(OS)•Kubeless(OS)

23Microservices and Serverless in Python projects

Aws lambda

24Microservices and Serverless in Python projects

25Microservices and Serverless in Python projects

Aws lambda functions

26Microservices and Serverless in Python projects

Aws lambda functions

27Microservices and Serverless in Python projects

Create lambda function with awscli

28Microservices and Serverless in Python projects

$ aws lambda create-function \--region eu-west-1 \--function-name MyHandler\--zip-file fileb://handler.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

29Microservices and Serverless in Python projects

30Microservices and Serverless in Python projects

Frameworks

31Microservices and Serverless in Python projects

python-λ

32Microservices and Serverless in Python projects

33Microservices and Serverless in Python projects

Zappa architecture

34Microservices and Serverless in Python projects

Zappa

35Microservices and Serverless in Python projects

36Microservices and Serverless in Python projects

37Microservices and Serverless in Python projects

38Microservices and Serverless in Python projects

39Microservices and Serverless in Python projects

# zappa_settings.json{

"dev": {"aws_region": "us-east-1","django_settings": "hello.settings","profile_name": "default","project_name": "hello","runtime": "python3.6","s3_bucket": "zappa-huyg6op0s"

}}

Zappa deploy

40Microservices and Serverless in Python projects

$ zappa deploy <env>

•Zips code and dependencies•Create AWS Lambda and deploys the zip•Creates endpoint on API Gateway and links to AWS Lambda

Zappa deploy

41Microservices and Serverless in Python projects

Zappa

42Microservices and Serverless in Python projects

Zappa Asynchronous Task

43Microservices and Serverless in Python projects

Chalice

44Microservices and Serverless in Python projects

•Python Serverless Microframework for AWS•Each endpoint is a separate function

Chalice

45Microservices and Serverless in Python projects

Chalice

46Microservices and Serverless in Python projects

Chalice example

47Microservices and Serverless in Python projects

Chalice methods

48Microservices and Serverless in Python projects

Resource HTTP Verb AWS Lambda

/talks GET get_talks

/talk POST add_new_talk

/talks/{ID} PUT update_talk

/talks/{ID} DELETE delete_talk

Chalice methods

49Microservices and Serverless in Python projects

Chalice options

50Microservices and Serverless in Python projects

Chalice deploy

51Microservices and Serverless in Python projects

Updating IAM policy.Updating lambda function...Regen deployment package...Sending changes to lambda.API Gateway rest API already found.Deploying to: dev

52Microservices and Serverless in Python projects

https://github.com/lambci/docker-lambda

53Microservices and Serverless in Python projects

http://serverlesscalc.com/

54Microservices and Serverless in Python projects

55Microservices and Serverless in Python projects

https://github.com/serverless/examples

56Microservices and Serverless in Python projects

References

57Microservices and Serverless in Python projects

•https://aws.amazon.com/blogs/compute/microservices-without-the-servers

•https://github.com/Miserlou/Zappa•https://github.com/pmuens/awesome-serverless

•https://github.com/aws/chalice•https://chalice.readthedocs.io/en/latest

58Microservices and Serverless in Python projects

Serverless architecture is the next generation of cloud evolution

Thank you!

José Manuel Ortegajmortega.github.io

top related