There’s a new class of applications that are becoming more prevalent these days: serverless applications. Serverless computing allows you to build and run applications without having to think about servers. Serverless apps don’t require you to provision or scale any servers.
How can we take advantage of serverless computing as python developers? What tools and frameworks are available that make writing serverless apps a breeze? And most importantly, how do we design and structure our applications in this serverless world to ensure we’re best utilizing the underlying services?
This is a practical talk on serverless architecture. In this talk, we’ll look at several serverless architecture patterns covering real world use cases. We’ll also look at actual open source serverless applications so we have concrete code examples we can review. These open source serverless applications leverage various AWS services including AWS Lambda and Amazon API Gateway.
Come learn how to design serverless applications in python so you can focus on writing your core applications rather than worrying about managing servers.
5. No servers to provision,
scale, or manage
Flexible scaling Built-in availability and fault tolerance
Serverless Computing
6. AWS Lambda
Run code without thinking about servers.
Pay for only the compute time you consume.
Lambda takes care of everything required to run and
scale your code with high availability.
10. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
2 event - data about what triggered invocation
context - runtime information about your function
11. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
12. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
app.py
13. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
app.py
14. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
app.py
$ python
>>> import app
>>> app.handler(event={}, context=None)
'hello world!'
15. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
app.py
16. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
app.py
$ pip install awscli
17. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
app.py
$ pip install awscli
$ aws configure
18. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
app.py
19. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
app.py
$ aws lambda create-function --function-name hello --handler app.handler --zip-file ...
20. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
app.py
$ aws lambda create-function --function-name hello --handler app.handler --zip-file ...
$ aws lambda invoke --function-name hello
21. def handler(event, context):
return 'hello world!'
AWS Lambda Function
1 Define python function
3 Return value sent back as response
2 event - data about what triggered invocation
context - runtime information about your function
app.py
$ aws lambda create-function --function-name hello --handler app.handler --zip-file ...
$ aws lambda invoke --function-name hello
hello world!
57. Lambda function invoked5
Stream/Poll Invocation
Stream Lambda Poller Lambda
Function execution finished
Return immediately2
Amazon SQS
message added
1
3 Poll for messages
Message batch4
58. Synchronous Asynchronous Stream
Blocks until response is returned
from Lambda function
Lambda function triggered in
response to an event, decoupled
from event trigger
Lambda service polls for
changes on a stream, invokes
Lambda function with batch of
messages
59. Synchronous Asynchronous Stream
Blocks until response is returned
from Lambda function
Lambda function triggered in
response to an event, decoupled
from event trigger
Lambda service polls for
changes on a stream, invokes
Lambda function with batch of
messages
$ aws lambda invoke
Amazon API Gateway
request
/users
60. Synchronous Asynchronous Stream
Blocks until response is returned
from Lambda function
Lambda function triggered in
response to an event, decoupled
from event trigger
Lambda service polls for
changes on a stream, invokes
Lambda function with batch of
messages
Timer
Amazon S3 Object
Amazon SNS Topic
$ aws lambda invoke
Amazon API Gateway
request
/users
61. Synchronous Asynchronous Stream
Blocks until response is returned
from Lambda function
Lambda function triggered in
response to an event, decoupled
from event trigger
Lambda service polls for
changes on a stream, invokes
Lambda function with batch of
messages
Timer
Amazon S3 Object
Amazon SNS Topic
Amazon SQS Message
Amazon DynamoDB Stream
Amazon Kinesis Stream
$ aws lambda invoke
Amazon API Gateway
request
/users
65. Setting up from scratch
AWS Lambda
AWS IAM role
IAM.create_role()IAM.put_role_policy()
Lambda.create_function()
Zip of code and
dependencies
IAM policy
66. Setting up from scratch
AWS Lambda
AWS IAM role
IAM.create_role()IAM.put_role_policy()
Lambda.create_function()
Zip of code and
dependencies
IAM policy
1
67. Setting up from scratch
AWS Lambda
AWS IAM role
IAM.create_role()IAM.put_role_policy()
Lambda.create_function()
Zip of code and
dependencies
IAM policy
1
2
68. Setting up from scratch
AWS Lambda
AWS IAM role
IAM.create_role()IAM.put_role_policy()
Lambda.create_function()
Zip of code and
dependencies
IAM policy
1
2
3
76. Amazon S3 AWS Lambda
AWS IAM role
IAM.create_role()IAM.put_role_policy()
Lambda.create_function()S3.put_bucket_notification_configuration()
Zip of code and
dependenciesNotification Config
IAM policy
Lambda.add_permsission(S3)
Image Resizer
77. Amazon S3 AWS Lambda
AWS IAM role
IAM.create_role()IAM.put_role_policy()
Lambda.create_function()S3.put_bucket_notification_configuration()
Zip of code and
dependenciesNotification Config
IAM policy
Lambda.add_permsission(S3)
Image Resizer
1. Third party packages
2. S3 notification configuration
3. IAM Permissions
78. Amazon S3 AWS Lambda
AWS IAM role
IAM.create_role()IAM.put_role_policy()
Lambda.create_function()S3.put_bucket_notification_configuration()
Zip of code and
dependenciesNotification Config
IAM policy
Lambda.add_permsission(S3)
Image Resizer
1. Third party packages
2. S3 notification configuration
3. IAM Permissions
79. Amazon S3 AWS Lambda
AWS IAM role
IAM.create_role()IAM.put_role_policy()
Lambda.create_function()S3.put_bucket_notification_configuration()
Zip of code and
dependenciesNotification Config
IAM policy
Lambda.add_permsission(S3)
Image Resizer
1. Third party packages
2. S3 notification configuration
3. IAM Permissions
80. Amazon S3 AWS Lambda
AWS IAM role
IAM.create_role()IAM.put_role_policy()
Lambda.create_function()S3.put_bucket_notification_configuration()
Zip of code and
dependenciesNotification Config
IAM policy
Lambda.add_permsission(S3)
Image Resizer
1. Third party packages
2. S3 notification configuration
3. IAM Permissions
81. AWS Chalice
Python serverless framework for AWS
Quickly create and deploy serverless applications
Integration with many AWS services
111. Continuous Delivery
Code changes are automatically built, tested, and
prepared for a release to production.
Every code change is built, tested, and then pushed to a
non-production testing or staging environment.
Deliver Updates Faster
112. Source Control Build Beta Production
Commit changes Run build and unit tests Deploy to test environment
Run integration tests
Deploy to production environment
113. Source Control Build Beta Production
Commit changes Run build and unit tests Deploy to test environment
Run integration tests
Deploy to production environment
114. Source Control Build Beta Production
Commit changes Run build and unit tests Deploy to test environment
Run integration tests
Deploy to production environment
115. Source Control Build Beta Production
Commit changes Run build and unit tests Deploy to test environment
Run integration tests
Deploy to production environment
116. Source Control Build Beta Production
Commit changes Run build and unit tests Deploy to test environment
Run integration tests
Deploy to production environment
120. Application Lifecycle
Local Dev Laptop
chalice local
Full CD Pipeline
Source
Build
Beta
Test
Prod
AWS CodePipeline
chalice generate-pipeline
Dev Stack
AWS Lambda
chalice deploy
Amazon S3
121. Next Steps
Todo App tutorial: https://chalice-workshop.readthedocs.io/en/latest/todo-app/index.html
Media query tutorial: https://chalice-workshop.readthedocs.io/en/latest/media-query/index.html
Chalice GitHub repository: https://github.com/aws/chalice
Chalice documentation: http://chalice.readthedocs.io/en/latest/
Serverless Black Belt (re:Invent 2017): https://www.youtube.com/watch?v=oQFORsso2go