SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
1.
Microservices and Serverless in
Python projects
José Manuel Ortega
Europython 2018
@jmortegac
v 0.5
2.
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
3.
Microservices vs Serverless
3Microservices and Serverless in Python projects
4.
Microservices
4Microservices and Serverless in Python projects
5.
Asynchronous calls with asyncio and aiohttp
5Microservices and Serverless in Python projects
6.
REST API Development
6Microservices and Serverless in Python projects
7.
Performance
7Microservices and Serverless in Python projects
8% less memory
6% faster response times
8.
Microservices with graphql
8Microservices and Serverless in Python projects
9.
9Microservices and Serverless in Python projects
10.
10Microservices and Serverless in Python projects
11.
11Microservices and Serverless in Python projects
12.
12Microservices and Serverless in Python projects
13.
13Microservices and Serverless in Python projects
SERVER
14.
14Microservices and Serverless in Python projects
CLIENT
15.
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
16.
16Microservices and Serverless in Python projects
Serverless
17.
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
18.
Serverless architecture
18Microservices and Serverless in Python projects
19.
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
20.
20Microservices and Serverless in Python projects
21.
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
22.
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
23.
Cloud providers
•AWS
•Microsoft Azure
•Cloud platform
•OpenWhisk(OS)
•Kubeless(OS)
23Microservices and Serverless in Python projects
24.
Aws lambda
24Microservices and Serverless in Python projects
25.
25Microservices and Serverless in Python projects
26.
Aws lambda functions
26Microservices and Serverless in Python projects
27.
Aws lambda functions
27Microservices and Serverless in Python projects
28.
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
29.
29Microservices and Serverless in Python projects
30.
30Microservices and Serverless in Python projects
31.
Frameworks
31Microservices and Serverless in Python projects
python-λ
32.
32Microservices and Serverless in Python projects
33.
33Microservices and Serverless in Python projects
34.
Zappa architecture
34Microservices and Serverless in Python projects
35.
Zappa
35Microservices and Serverless in Python projects
36.
36Microservices and Serverless in Python projects
37.
37Microservices and Serverless in Python projects
38.
38Microservices and Serverless in Python projects
40.
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
41.
Zappa deploy
41Microservices and Serverless in Python projects
42.
Zappa
42Microservices and Serverless in Python projects
43.
Zappa Asynchronous Task
43Microservices and Serverless in Python projects
44.
Chalice
44Microservices and Serverless in Python projects
•Python Serverless Microframework for AWS
•Each endpoint is a separate function
45.
Chalice
45Microservices and Serverless in Python projects
46.
Chalice
46Microservices and Serverless in Python projects
47.
Chalice example
47Microservices and Serverless in Python projects
48.
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
49.
Chalice methods
49Microservices and Serverless in Python projects
50.
Chalice options
50Microservices and Serverless in Python projects
51.
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
52.
52Microservices and Serverless in Python projects
53.
https://github.com/lambci/docker-lambda
53Microservices and Serverless in Python projects
54.
http://serverlesscalc.com/
54Microservices and Serverless in Python projects
55.
55Microservices and Serverless in Python projects
56.
https://github.com/serverless/examples
56Microservices and Serverless in Python projects
57.
References
57Microservices and Serverless in Python projects
•https://aws.amazon.com/blogs/compute/microservic
es-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
58.
58Microservices and Serverless in Python projects
Serverless architecture is the
next generation of cloud
evolution
59.
Thank you!
José Manuel Ortega
jmortega.github.io