Contenu connexe Similaire à Building Serverless Microservices with AWS (20) Plus de Donnie Prakoso (7) Building Serverless Microservices with AWS1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Donnie Prakoso, MSc
AWS Technology Evangelist, ASEAN
Building Serverless Microservices
AWS User Group Meetup
@donnieprakoso
2. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hello, World.
Donnie Prakoso, MSc
AWS Technology Evangelist, ASEAN
@donnieprakoso
donnieprakoso
• Speak in Go and Python
• Machine Learning and Serverless
• I AWS User Groups
3. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Let’s Discuss Something
• What is microservices and why we
should consider to adopt it?
• What are the options we have to
implement it?
• How can we build, deploy and
coordinate microservices?
4. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What Is Microservices?
5. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
What Is Microservices?
An approach to developing a single application as a suite of
small services, each running in its own process and
communicating with lightweight mechanisms, often an HTTP
resource API
- Martin Fowler & James Lewis
https://martinfowler.com
6. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Monolithic vs. Microservices
webserver
.package
Order UI
Order service
Inventory
service
Shipping
service
Order
UI
Inventory
service
Order
service
Shipping
service
7. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Image credits: Ikea
8. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Image credits: Ikea
9. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Tenets of Microservices Architectures
Do one
thing wellIndependent
Decentralized
Black box
Polyglot
You build it, you run it
10. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Demo
11. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Benefits of Microservices Architecture
Agility
Flexible
scaling
Easy
deployment
Technology
freedom
Reusable code
Resilience
12. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
What Are Our Options?
Amazon EC2 Amazon ECS AWS Lambda
INSTANCES CONTAINERS SERVERLESS
13. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless Means …
No servers to provision
or manage
Scales with usage
Never pay for idle Built in availability and
fault tolerance
14. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Focus on building business logic.
!
15. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Services for Building Serverless Applications
AWS Lambda
Amazon DynamoDB
Amazon SNS
Amazon API Gateway
Amazon SQS
Amazon Kinesis
Amazon S3
Compute and API Proxy
AWS X-Ray
AWS Step Functions
Datastores, Storage, Orchestration, Analytics, Interprocess Messaging
Developer Tools
AWS CodeBuild
AWS CodePipeline
AWS Serverless
Application Model (SAM)
Open Source and
third parties
Lambda@Edge
AWS Cloud9
Amazon Aurora
Serverless (preview)
AWS AppSync
16. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Common Serverless Application Use Cases
Web
applications
• Static
websites
• Complex web
apps
• Packages for
Flask and
Express
Data
processing
• Real-time
• MapReduce
• Batch
• Machine
learning
inference
Chatbots
• Powering
chatbot logic
Backends
• Apps and
services
• Mobile
• IoT
</></>
Amazon
Alexa
• Powering
voice-enabled
apps
• Alexa
Skills Kit
IT
automation
• Policy engines
• Extending
AWS services
• Infrastructure
management
17. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Using AWS Lambda
Bring your own code
• Node.js, Java, Python,
C#, Go
• Bring your own libraries
(even native ones)
Simple resource model
• Select power rating from
128 MB to 3 GB
• CPU and network
allocated proportionately
Flexible use
• Synchronous or
asynchronous
• Integrated with other
AWS services
Flexible authorization
• Securely grant access to
resources and VPCs
• Fine-grained control for
invoking your functions
18. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Using AWS Lambda
Authoring functions
• WYSIWYG editor or
upload packaged .zip
• AWS Cloud9 IDE
• Third-party plugins
(Eclipse, Visual Studio)
Monitoring and logging
• Metrics for requests,
errors, and throttles
• Built-in logs to Amazon
CloudWatch Logs
• Distributed tracing with
AWS X-Ray
Programming model
• Use processes, threads,
/tmp, sockets normally
• AWS SDK built in
(Python and Node.js)
Stateless
• Persist data using
external storage
• No affinity or access to
underlying infrastructure
19. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless is a relatively better fit
for microservices.
!
20. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Development and Deployment.
1
21. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Serverless Application Model (SAM)
Simplified template driven deployment
model for serverless applications
Supported serverless resource types:
functions, APIs, and tables
Supports anything AWS CloudFormation
supports
Open specification (Apache 2.0)
https://github.com/awslabs/serverless-application-model
22. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SAM Template
Tells CloudFormation this is a SAM
template it needs to transform
Creates a Lambda function with the
referenced managed IAM policy,
runtime, code at the referenced zip
location, and handler as defined.
Also creates an API Gateway and
takes care of all
mapping/permissions necessary
Creates a DynamoDB table with five
read & write units
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.gethtml
Runtime: nodejs4.3
Policies: AmazonDynamoDBReadOnlyAccess
Events:
GetHtml:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
ListTable:
Type: AWS::Serverless::SimpleTable
23. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SAM commands—package & deploy
Package
•Creates a deployment package (.zip file)
•Uploads deployment package to an Amazon S3 bucket
•Adds a CodeUri property with S3 URI
Deploy
•Calls AWS CloudFormation ‘CreateChangeSet’ API
•Calls AWS CloudFormation ‘ExecuteChangeSet’ API
24. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS SAM CLI
CLI tool for local testing of serverless apps
Works with Lambda functions and “proxy-
style” APIs
Response object and function logs
available on your local machine
Uses open source docker-lambda images
to mimic Lambda’s execution environment:
• Emulates timeout, memory limits,
runtimes
https://github.com/awslabs/aws-sam-local
25. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Integration with AWS Services.
2
26. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway
Create a unified
API frontend for
multiple
microservices
Authenticate and
authorize
requests to a
backend
DDoS protection
and throttling
for your backend
Throttle, meter,
and monetize
API usage by
third-party
developers
27. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless Applications
Services (anything)
Changes in
data state
Requests to
endpoints
Changes in
resource state
Event source Lambda function
Node.js
Python
Java
C#
Go
28. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon S3 Amazon
DynamoDB
Amazon
Kinesis
AWS
CloudFormation
AWS CloudTrail Amazon
CloudWatch
Amazon
Cognito
Amazon SNSAmazon
SES
Cron events
DATA STORES ENDPOINTS
CONFIGURATION REPOSITORIES EVENT/MESSAGE SERVICES
Example event sources that trigger AWS Lambda
… and a few more with more on the way!
AWS
CodeCommit
Amazon
API Gateway
Amazon
Alexa
AWS IoT AWS Step
Functions
29. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda execution model
Synchronous
(push)
Asynchronous
(event)
Stream-based
Amazon
API Gateway
AWS Lambda
function
Amazon
DynamoDBAmazon
SNS
/order
AWS Lambda
function
Amazon
S3
reqs
Amazon
Kinesis
changes
AWS Lambda
service
function
30. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Secrets Manager
Rotate secrets safely Secure and audit
secrets centrally
Manage access with
fine-grained policies
Easily rotate, manage, and retrieve database credentials, API keys, and
other secrets through their lifecycle
31. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Microservices Coordination
3
32. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Step Functions
Easily coordinate multiple Lambda functions using visual
workflows
Visualize in the
console
Define in JSON Monitor
executions
33. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
State Example: Task
34. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
State Example: Choice
35. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
State Example: Succeed / Fail
36. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
State Example: Pass
37. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
State Example: Wait
38. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
State Example: Parallel
39. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Demo
40. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Benefits of Step Functions Orchestration
Change and add steps
without writing code
to evolve applications
and innovate faster
Coordinate and visualize
Lambda functions as a
series of steps to quickly
create serverless apps
Automatically trigger and
track each step at scale
and handle errors with
built-in retry and fallback
Productivity AgilityResilience
41. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Quiz
AWS
? ?
?
Credential
?
Static Website
User
42. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Build On!
Donnie Prakoso
@donnieprakoso