SlideShare une entreprise Scribd logo
1  sur  55
Télécharger pour lire hors ligne
Serverless Microservices
An introduction to AWS Lambda and the Serverless Framework
© Rowell Belen 1
About Me
Rowell Belen / Software Engineer @ Stedi
» LinkedIn: https://linkedin.com/in/rowellbelen
» Blog: https://www.rowellbelen.com
» GitHub: https://github.com/bytekast
» Twitter: @bytekast
» Email: rowell.belen@bytekast.com
© Rowell Belen 2
What is Serverless Computing?
Serverless Computing is a cloud computing model that allows
you to build and run applications and services without thinking
about servers. The platform takes care of everything required to
run and scale your code with high availability.
© Rowell Belen 3
The Sweet Spot
© Rowell Belen 4
But... but... aren't PaaS and Serverless the same?
© Rowell Belen 5
What is the key
difference between
PaaS and Serverless?
© Rowell Belen 6
SCALING!!
© Rowell Belen 7
Unit of Scale
» Data Center: Hardware (Physical Hosting Env Abstraction)
» IaaS: Virtual Machines (Hardware Abstraction)
» Paas: Application (VM Abstraction)
» Serverless: Function (Runtime Abstraction)
© Rowell Belen 8
Wait.. wait... What about containers?
© Rowell Belen 9
What are the key
differences between
Containers and Serverless?
© Rowell Belen 10
ORCHESTRATION
&
MANAGEMENT
© Rowell Belen 11
and...
SCALING!!
© Rowell Belen 12
What is AWS Lambda?
Amazon's Serverless compute platform for stateless code
execution in response to events
© Rowell Belen 13
Other Serverless Platform Providers
» Microsoft Azure Functions
» Iron.io
» Google Cloud Functions
» IBM Open Whisk
» WebTask.io
» PubNub BLOCKS
© Rowell Belen 14
How Is AWS Lambda Used?
» Stream Data Processing
» REST Backend Services
» One-off Processes
» Background Workers
» Event Responders
© Rowell Belen 15
How are Lambda Functions Triggered?
» Event-driven (SNS, S3, API-Gateway, Amazon Echo Skills, IoT,
etc.)
» Direct Invocation (CLI, SDK, etc.)
» Scheduled Interval
© Rowell Belen 16
Supported Languages
» Node.js (Javascript)
» Python
» JVM ( Java, Scala, Groovy, Kotlin, Clojure, etc. )
» C#
© Rowell Belen 17
Pricing
Memory (MB) Free tier seconds per month Price per 100ms ($)
128 3,200,000 0.000000208
256 1,600,000 0.000000417
512 800,000 0.000000834
1024 400,000 0.000001667
1536 266,667 0.000002501
© Rowell Belen 18
Top Tier Pricing (1536 MB Memory)
1 Million Executions @ 1 sec/exec ≈ $18.34
© Rowell Belen 19
Benefits
» Cost and Utilization
» Fully Managed Infrastructure
» Rapid Development
» Streamlined AWS Integrations
» Pay Per Use
» Auto Scale
» Built-in Versioning
© Rowell Belen 20
Drawbacks
» Limited Language Support
» Not Suitable for Long-running Tasks
» Local Development and Debugging Challenges
» Limited Infrastructure Transparency / Less Control
» Potential Vendor Lock-in
» Cutting-edge quirks
» Concurrent Execution Limit is Shared across entire AWS
© Rowell Belen 21
Serverless @
© Rowell Belen 22
© Rowell Belen 23
Enough chit-chat,
let's see some code!
© Rowell Belen 24
Send Events/Metrics to Datadog
class DatadogHandler {
final rest = new RESTClient('https://app.datadoghq.com/')
void handleRequest(Map input, Context context) {
def jsonObj = snsJsonBody(input) // Extract Payload
def type = jsonObj?.'alert_type' ? 'events' : 'series'
def query = ['api_key': System.getenv('DATADOG_API_KEY')]
rest.post(
path: "api/v1/${type}",
body: jsonObj,
query: query
)
}
}
© Rowell Belen 25
Custom JWT Token Authorizer
class AuthorizerHandler {
Map handleRequest(Map input, Context context) {
// extract token and resource from input
def token = input.authorizationToken?.minus('Bearer')?.trim()
def resource = input.methodArn
// authenticate
def claims = verifyToken(token)
// return policy
createPolicy(claims, resource)
}
}
© Rowell Belen 26
Verify Token (cont.)
Map verifyToken(final String token) {
def algorithm = Algorithm.HMAC256(System.getenv('AUTH0_CLIENT_SECRET'))
def verifier = JWT.require(algorithm).build()
def decodedJwt = verifier.verify(token)
decodedJwt.getClaims()
}
© Rowell Belen 27
Create Security Policy with Claims (cont.)
Map createPolicy(final Map claims, final String resource) {
[
principalId : claims?.user_id,
policyDocument: [
Version : '2012-10-17',
Statement: [
Action : 'execute-api:Invoke',
Effect : claims ? 'Allow' : 'Deny',
Resource: resource
]
],
context : claims
]
}
© Rowell Belen 28
How do I invoke a Lambda function
programatically?
© Rowell Belen 29
Direct Lambda Invocation - Define Interfaces
interface DocumentAuditService {
@LambdaFunction(invocationType = InvocationType.Event, functionName = 'document-audit')
void audit(DocumentAudit documentAudit)
}
class DocumentAudit {
String documentId
String status
}
© Rowell Belen 30
Direct Lambda Invocation (cont...) - Use a Proxy
void handle(Document document, Context context) {
// Do something with the document...
// Create proxy to DocumentAuditService
def docService = LambdaInvokerFactory.builder()
.lambdaClient(AWSLambdaClientBuilder.defaultClient())
.build(DocumentAuditService.class) // pass the interface
// Call audit lambda function
docService.audit(
new DocumentAudit(documentId: UUID.randomUUID().toString(), status: 'TRANSMITTED'))
}
© Rowell Belen 31
What is the Serverless Framework?
Development toolkit for building, managing and deploying
Serverless applications and resources
© Rowell Belen 32
Serverless Framework CLI
npm install serverless -g
mkdir my-api && cd my-api
serverless create --template aws-groovy-gradle
serverless deploy --stage dev
serverless invoke --function my-function --log
© Rowell Belen 33
Available Templates
» aws-nodejs
» aws-python
» aws-groovy-gradle
» aws-java-maven
» aws-java-gradle
» aws-scala-sbt
© Rowell Belen 34
serverless.yml - Basic Function
service: serverless-demo
provider:
runtime: java8
timeout: 300
memorySize: 1536
package:
artifact: /build/dist/serverless-demo.zip
functions:
my-function:
handler: com.bytekast.serverless.MyLambdaFunction::handler
© Rowell Belen 35
serverless.yml - API Gateway
functions:
createUser:
handler: com.bytekast.serverless.UserService::createUser
events:
- http:
path: users/create
method: post
deleteUser:
handler: com.bytekast.serverless.UserService::deleteUser
events:
- http:
path: users/delete
method: delete
© Rowell Belen 36
serverless.yml - API Gateway (Custom Authorization)
...
events:
- http:
path: users/create
method: post
cors: true
authorizer:
arn: arn:aws:lambda:us-east-1:1234567890123:function:authorizer
identitySource: method.request.header.Authorization
identityValidationExpression: Bearer .*
© Rowell Belen 37
serverless.yml - SNS Topic Subscription
functions:
audit:
handler: com.bytekast.serverless.AuditService::audit
events:
- sns: dev-audit-topic
© Rowell Belen 38
serverless.yml - Scheduled Trigger
functions:
crawl:
handler: com.bytekast.serverless.SearchService::crawl
events:
- schedule: rate(2 hours)
- schedule: cron(0 12 * * ? *)
© Rowell Belen 39
serverless.yml - IAM Role Permissions
provider:
...
iamRoleStatements:
- Effect: "Allow"
Action:
- "sqs:*"
Resource: arn:aws:sqs:us-east-1:1234567890123:dev-serverless-demo
© Rowell Belen 40
serverless.yml - Create AWS Resources
resources:
Resources:
InboundQueue:
Type: "AWS::SQS::Queue"
Properties:
QueueName: ${self:provider.stage}-serverless-demo
MessageRetentionPeriod: 1209600
VisibilityTimeout: 60
© Rowell Belen 41
DEMO
Build Slack Command API using
Serverless Framework + API Gateway + AWS Lambda
https://github.com/bytekast/serverless-demo
© Rowell Belen 42
What about Cloud Scale
DevOps?
© Rowell Belen 43
Infrastructure and Environment
configurations need to be reproducible
from a definition under source control
© Rowell Belen 44
Solution:
© Rowell Belen 45
Immutable Infrastructure?
Immutable components are replaced for every deployment, rather than
being updated in-place
© Rowell Belen 46
Solution: Lambda Built-In Features
» Containers are ephemeral entities that are easily created and
destroyed
» Preserved history and ability to roll back a bad deployment
( revert to previous version )
» Auto-managed horizontal scaling (Scale out / Scale In)
» Automatic Load Balancing
» Zero/Minimal Downtime during deployment
© Rowell Belen 47
Environments should not be connected
or otherwise intercommunicate
© Rowell Belen 48
Solutions:
» AWS Lambda supports running functions in different VPCs
(dev, stage, prod)
» Use separate AWS accounts per Environment
© Rowell Belen 49
Promote immutable application
artifacts from the lowest environment
to the highest ( Deployment )
© Rowell Belen 50
Solutions:
» Publish Versioned Build Artifacts to Repository
» Continuous Integration
» Continuous Delivery
© Rowell Belen 51
Centralized Logging
© Rowell Belen 52
Metrics
» Better Dashboards
» Custom Metrics and Events
© Rowell Belen 53
Other Things to Consider
» AWS functions are recycled about every 8 hours
» Container instances idle for about 5 minutes are destroyed
» Cold starts can cause delay in response times
» 50 MB max deployment package size
» 5 minute running time limit
» 1000 default concurrent function executions across entire
AWS account
© Rowell Belen 54
Questions?
© Rowell Belen 55

Contenu connexe

Tendances

Tensorflow in production with AWS Lambda
Tensorflow in production with AWS LambdaTensorflow in production with AWS Lambda
Tensorflow in production with AWS LambdaFabian Dubois
 
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Seven Peaks Speaks
 
Netflix Cloud Platform and Open Source
Netflix Cloud Platform and Open SourceNetflix Cloud Platform and Open Source
Netflix Cloud Platform and Open Sourceaspyker
 
End-to-end test automation with Endtest.dev
End-to-end test automation with Endtest.devEnd-to-end test automation with Endtest.dev
End-to-end test automation with Endtest.devKonstantin Tarkus
 
Kubernetes for Serverless - Serverless Summit 2017 - Krishna Kumar
Kubernetes for Serverless  - Serverless Summit 2017 - Krishna KumarKubernetes for Serverless  - Serverless Summit 2017 - Krishna Kumar
Kubernetes for Serverless - Serverless Summit 2017 - Krishna KumarCodeOps Technologies LLP
 
Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020Andrea Scuderi
 
Serverless Framework (2018)
Serverless Framework (2018)Serverless Framework (2018)
Serverless Framework (2018)Rowell Belen
 
NetflixOSS and ZeroToDocker Talk
NetflixOSS and ZeroToDocker TalkNetflixOSS and ZeroToDocker Talk
NetflixOSS and ZeroToDocker Talkaspyker
 
Large Scale Kubernetes on AWS at Europe's Leading Online Fashion Platform - A...
Large Scale Kubernetes on AWS at Europe's Leading Online Fashion Platform - A...Large Scale Kubernetes on AWS at Europe's Leading Online Fashion Platform - A...
Large Scale Kubernetes on AWS at Europe's Leading Online Fashion Platform - A...Henning Jacobs
 
Lessons learned after a year of lambda - AWS Community Day SF 2017
Lessons learned after a year of lambda - AWS Community Day SF 2017Lessons learned after a year of lambda - AWS Community Day SF 2017
Lessons learned after a year of lambda - AWS Community Day SF 2017Matt Billock
 
Riga DevDays 2017 - Efficient AWS Lambda
Riga DevDays 2017 - Efficient AWS LambdaRiga DevDays 2017 - Efficient AWS Lambda
Riga DevDays 2017 - Efficient AWS LambdaAntons Kranga
 
Aws serverless architecture
Aws serverless architectureAws serverless architecture
Aws serverless architecturegenesesoftware
 
Velocity NYC 2016 - Containers @ Netflix
Velocity NYC 2016 - Containers @ NetflixVelocity NYC 2016 - Containers @ Netflix
Velocity NYC 2016 - Containers @ Netflixaspyker
 
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019Haufe-Lexware GmbH & Co KG
 
AWS Community Day Bangkok 2019 - Dev Ops Philosophy Increase Productivity
AWS Community Day Bangkok 2019 - Dev Ops Philosophy Increase ProductivityAWS Community Day Bangkok 2019 - Dev Ops Philosophy Increase Productivity
AWS Community Day Bangkok 2019 - Dev Ops Philosophy Increase ProductivityAWS User Group - Thailand
 
Serverless Reality
Serverless RealityServerless Reality
Serverless RealityLynn Langit
 

Tendances (20)

Node withoutservers aws-lambda
Node withoutservers aws-lambdaNode withoutservers aws-lambda
Node withoutservers aws-lambda
 
IaC on AWS Cloud
IaC on AWS CloudIaC on AWS Cloud
IaC on AWS Cloud
 
Tensorflow in production with AWS Lambda
Tensorflow in production with AWS LambdaTensorflow in production with AWS Lambda
Tensorflow in production with AWS Lambda
 
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
 
Netflix Cloud Platform and Open Source
Netflix Cloud Platform and Open SourceNetflix Cloud Platform and Open Source
Netflix Cloud Platform and Open Source
 
End-to-end test automation with Endtest.dev
End-to-end test automation with Endtest.devEnd-to-end test automation with Endtest.dev
End-to-end test automation with Endtest.dev
 
Kubernetes for Serverless - Serverless Summit 2017 - Krishna Kumar
Kubernetes for Serverless  - Serverless Summit 2017 - Krishna KumarKubernetes for Serverless  - Serverless Summit 2017 - Krishna Kumar
Kubernetes for Serverless - Serverless Summit 2017 - Krishna Kumar
 
Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020Aws Lambda in Swift - NSLondon - 3rd December 2020
Aws Lambda in Swift - NSLondon - 3rd December 2020
 
Serverless Framework (2018)
Serverless Framework (2018)Serverless Framework (2018)
Serverless Framework (2018)
 
NetflixOSS and ZeroToDocker Talk
NetflixOSS and ZeroToDocker TalkNetflixOSS and ZeroToDocker Talk
NetflixOSS and ZeroToDocker Talk
 
Serverless Summit - Quiz
Serverless Summit - QuizServerless Summit - Quiz
Serverless Summit - Quiz
 
Large Scale Kubernetes on AWS at Europe's Leading Online Fashion Platform - A...
Large Scale Kubernetes on AWS at Europe's Leading Online Fashion Platform - A...Large Scale Kubernetes on AWS at Europe's Leading Online Fashion Platform - A...
Large Scale Kubernetes on AWS at Europe's Leading Online Fashion Platform - A...
 
Lessons learned after a year of lambda - AWS Community Day SF 2017
Lessons learned after a year of lambda - AWS Community Day SF 2017Lessons learned after a year of lambda - AWS Community Day SF 2017
Lessons learned after a year of lambda - AWS Community Day SF 2017
 
ASP.NET vNext
ASP.NET vNextASP.NET vNext
ASP.NET vNext
 
Riga DevDays 2017 - Efficient AWS Lambda
Riga DevDays 2017 - Efficient AWS LambdaRiga DevDays 2017 - Efficient AWS Lambda
Riga DevDays 2017 - Efficient AWS Lambda
 
Aws serverless architecture
Aws serverless architectureAws serverless architecture
Aws serverless architecture
 
Velocity NYC 2016 - Containers @ Netflix
Velocity NYC 2016 - Containers @ NetflixVelocity NYC 2016 - Containers @ Netflix
Velocity NYC 2016 - Containers @ Netflix
 
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
Haufe Onboarding - Fast Iterating With the MERN Stack - TEC Day 2019
 
AWS Community Day Bangkok 2019 - Dev Ops Philosophy Increase Productivity
AWS Community Day Bangkok 2019 - Dev Ops Philosophy Increase ProductivityAWS Community Day Bangkok 2019 - Dev Ops Philosophy Increase Productivity
AWS Community Day Bangkok 2019 - Dev Ops Philosophy Increase Productivity
 
Serverless Reality
Serverless RealityServerless Reality
Serverless Reality
 

Similaire à Microservices with AWS Lambda and the Serverless Framework

Zero to Serverless in 60s - Anywhere
Zero to Serverless in 60s - AnywhereZero to Serverless in 60s - Anywhere
Zero to Serverless in 60s - AnywhereBrian Christner
 
Containerize, PaaS, or Go Serverless!?
Containerize, PaaS, or Go Serverless!?Containerize, PaaS, or Go Serverless!?
Containerize, PaaS, or Go Serverless!?Phil Estes
 
.NET Cloud-Native Bootcamp- Los Angeles
.NET Cloud-Native Bootcamp- Los Angeles.NET Cloud-Native Bootcamp- Los Angeles
.NET Cloud-Native Bootcamp- Los AngelesVMware Tanzu
 
PHP Buildpacks in the Cloud on Bluemix
PHP Buildpacks in the Cloud on BluemixPHP Buildpacks in the Cloud on Bluemix
PHP Buildpacks in the Cloud on BluemixIBM
 
Cloud Foundry for PHP developers
Cloud Foundry for PHP developersCloud Foundry for PHP developers
Cloud Foundry for PHP developersDaniel Krook
 
Architecture: When, how, and if to Adopt Microservices
Architecture: When, how, and if to Adopt MicroservicesArchitecture: When, how, and if to Adopt Microservices
Architecture: When, how, and if to Adopt MicroservicesAmazon Web Services
 
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Emerson Eduardo Rodrigues Von Staffen
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...Amazon Web Services
 
Serverless: The next major shift in cloud computing
Serverless: The next major shift in cloud computingServerless: The next major shift in cloud computing
Serverless: The next major shift in cloud computingDoug Vanderweide
 
Docker vs. Kubernetes vs. Serverless
Docker vs. Kubernetes vs. ServerlessDocker vs. Kubernetes vs. Serverless
Docker vs. Kubernetes vs. ServerlessLogicworksNY
 
Tech Talk: DevOps at LeanIX @ Startup Camp Berlin
Tech Talk: DevOps at LeanIX @ Startup Camp BerlinTech Talk: DevOps at LeanIX @ Startup Camp Berlin
Tech Talk: DevOps at LeanIX @ Startup Camp BerlinLeanIX GmbH
 
Moving Applications into Azure Kubernetes
Moving Applications into Azure KubernetesMoving Applications into Azure Kubernetes
Moving Applications into Azure KubernetesHussein Salman
 
DevOps and BigData Analytics
DevOps and BigData Analytics DevOps and BigData Analytics
DevOps and BigData Analytics sbbabu
 
2020-02-10 Java on Azure Solution Briefing
2020-02-10 Java on Azure Solution Briefing2020-02-10 Java on Azure Solution Briefing
2020-02-10 Java on Azure Solution BriefingEd Burns
 
Proof of Concept: Serverless with Swarm by Nirmal Mehta, Booz Allen Hamilton
Proof of Concept: Serverless with Swarm by Nirmal Mehta, Booz Allen Hamilton Proof of Concept: Serverless with Swarm by Nirmal Mehta, Booz Allen Hamilton
Proof of Concept: Serverless with Swarm by Nirmal Mehta, Booz Allen Hamilton Docker, Inc.
 
AWS Summit 2013 | Auckland - Continuous Deployment Practices, with Production...
AWS Summit 2013 | Auckland - Continuous Deployment Practices, with Production...AWS Summit 2013 | Auckland - Continuous Deployment Practices, with Production...
AWS Summit 2013 | Auckland - Continuous Deployment Practices, with Production...Amazon Web Services
 
AWS Webcast - Build Agile Applications in AWS Cloud for Government
AWS Webcast - Build Agile Applications in AWS Cloud for GovernmentAWS Webcast - Build Agile Applications in AWS Cloud for Government
AWS Webcast - Build Agile Applications in AWS Cloud for GovernmentAmazon Web Services
 
Global Azure Bootcamp 2017 at Betabit Utrecht
Global Azure Bootcamp 2017 at Betabit UtrechtGlobal Azure Bootcamp 2017 at Betabit Utrecht
Global Azure Bootcamp 2017 at Betabit UtrechtDaniël te Winkel
 
GIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud ServicesGIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud ServicesPatrick Chanezon
 

Similaire à Microservices with AWS Lambda and the Serverless Framework (20)

Zero to Serverless in 60s - Anywhere
Zero to Serverless in 60s - AnywhereZero to Serverless in 60s - Anywhere
Zero to Serverless in 60s - Anywhere
 
56k.cloud training
56k.cloud training56k.cloud training
56k.cloud training
 
Containerize, PaaS, or Go Serverless!?
Containerize, PaaS, or Go Serverless!?Containerize, PaaS, or Go Serverless!?
Containerize, PaaS, or Go Serverless!?
 
.NET Cloud-Native Bootcamp- Los Angeles
.NET Cloud-Native Bootcamp- Los Angeles.NET Cloud-Native Bootcamp- Los Angeles
.NET Cloud-Native Bootcamp- Los Angeles
 
PHP Buildpacks in the Cloud on Bluemix
PHP Buildpacks in the Cloud on BluemixPHP Buildpacks in the Cloud on Bluemix
PHP Buildpacks in the Cloud on Bluemix
 
Cloud Foundry for PHP developers
Cloud Foundry for PHP developersCloud Foundry for PHP developers
Cloud Foundry for PHP developers
 
Architecture: When, how, and if to Adopt Microservices
Architecture: When, how, and if to Adopt MicroservicesArchitecture: When, how, and if to Adopt Microservices
Architecture: When, how, and if to Adopt Microservices
 
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
 
Serverless: The next major shift in cloud computing
Serverless: The next major shift in cloud computingServerless: The next major shift in cloud computing
Serverless: The next major shift in cloud computing
 
Docker vs. Kubernetes vs. Serverless
Docker vs. Kubernetes vs. ServerlessDocker vs. Kubernetes vs. Serverless
Docker vs. Kubernetes vs. Serverless
 
Tech Talk: DevOps at LeanIX @ Startup Camp Berlin
Tech Talk: DevOps at LeanIX @ Startup Camp BerlinTech Talk: DevOps at LeanIX @ Startup Camp Berlin
Tech Talk: DevOps at LeanIX @ Startup Camp Berlin
 
Moving Applications into Azure Kubernetes
Moving Applications into Azure KubernetesMoving Applications into Azure Kubernetes
Moving Applications into Azure Kubernetes
 
DevOps and BigData Analytics
DevOps and BigData Analytics DevOps and BigData Analytics
DevOps and BigData Analytics
 
2020-02-10 Java on Azure Solution Briefing
2020-02-10 Java on Azure Solution Briefing2020-02-10 Java on Azure Solution Briefing
2020-02-10 Java on Azure Solution Briefing
 
Proof of Concept: Serverless with Swarm by Nirmal Mehta, Booz Allen Hamilton
Proof of Concept: Serverless with Swarm by Nirmal Mehta, Booz Allen Hamilton Proof of Concept: Serverless with Swarm by Nirmal Mehta, Booz Allen Hamilton
Proof of Concept: Serverless with Swarm by Nirmal Mehta, Booz Allen Hamilton
 
AWS Summit 2013 | Auckland - Continuous Deployment Practices, with Production...
AWS Summit 2013 | Auckland - Continuous Deployment Practices, with Production...AWS Summit 2013 | Auckland - Continuous Deployment Practices, with Production...
AWS Summit 2013 | Auckland - Continuous Deployment Practices, with Production...
 
AWS Webcast - Build Agile Applications in AWS Cloud for Government
AWS Webcast - Build Agile Applications in AWS Cloud for GovernmentAWS Webcast - Build Agile Applications in AWS Cloud for Government
AWS Webcast - Build Agile Applications in AWS Cloud for Government
 
Global Azure Bootcamp 2017 at Betabit Utrecht
Global Azure Bootcamp 2017 at Betabit UtrechtGlobal Azure Bootcamp 2017 at Betabit Utrecht
Global Azure Bootcamp 2017 at Betabit Utrecht
 
GIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud ServicesGIDS 2019: Developing Apps with Containers, Functions and Cloud Services
GIDS 2019: Developing Apps with Containers, Functions and Cloud Services
 

Dernier

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 

Dernier (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 

Microservices with AWS Lambda and the Serverless Framework

  • 1. Serverless Microservices An introduction to AWS Lambda and the Serverless Framework © Rowell Belen 1
  • 2. About Me Rowell Belen / Software Engineer @ Stedi » LinkedIn: https://linkedin.com/in/rowellbelen » Blog: https://www.rowellbelen.com » GitHub: https://github.com/bytekast » Twitter: @bytekast » Email: rowell.belen@bytekast.com © Rowell Belen 2
  • 3. What is Serverless Computing? Serverless Computing is a cloud computing model that allows you to build and run applications and services without thinking about servers. The platform takes care of everything required to run and scale your code with high availability. © Rowell Belen 3
  • 4. The Sweet Spot © Rowell Belen 4
  • 5. But... but... aren't PaaS and Serverless the same? © Rowell Belen 5
  • 6. What is the key difference between PaaS and Serverless? © Rowell Belen 6
  • 8. Unit of Scale » Data Center: Hardware (Physical Hosting Env Abstraction) » IaaS: Virtual Machines (Hardware Abstraction) » Paas: Application (VM Abstraction) » Serverless: Function (Runtime Abstraction) © Rowell Belen 8
  • 9. Wait.. wait... What about containers? © Rowell Belen 9
  • 10. What are the key differences between Containers and Serverless? © Rowell Belen 10
  • 13. What is AWS Lambda? Amazon's Serverless compute platform for stateless code execution in response to events © Rowell Belen 13
  • 14. Other Serverless Platform Providers » Microsoft Azure Functions » Iron.io » Google Cloud Functions » IBM Open Whisk » WebTask.io » PubNub BLOCKS © Rowell Belen 14
  • 15. How Is AWS Lambda Used? » Stream Data Processing » REST Backend Services » One-off Processes » Background Workers » Event Responders © Rowell Belen 15
  • 16. How are Lambda Functions Triggered? » Event-driven (SNS, S3, API-Gateway, Amazon Echo Skills, IoT, etc.) » Direct Invocation (CLI, SDK, etc.) » Scheduled Interval © Rowell Belen 16
  • 17. Supported Languages » Node.js (Javascript) » Python » JVM ( Java, Scala, Groovy, Kotlin, Clojure, etc. ) » C# © Rowell Belen 17
  • 18. Pricing Memory (MB) Free tier seconds per month Price per 100ms ($) 128 3,200,000 0.000000208 256 1,600,000 0.000000417 512 800,000 0.000000834 1024 400,000 0.000001667 1536 266,667 0.000002501 © Rowell Belen 18
  • 19. Top Tier Pricing (1536 MB Memory) 1 Million Executions @ 1 sec/exec ≈ $18.34 © Rowell Belen 19
  • 20. Benefits » Cost and Utilization » Fully Managed Infrastructure » Rapid Development » Streamlined AWS Integrations » Pay Per Use » Auto Scale » Built-in Versioning © Rowell Belen 20
  • 21. Drawbacks » Limited Language Support » Not Suitable for Long-running Tasks » Local Development and Debugging Challenges » Limited Infrastructure Transparency / Less Control » Potential Vendor Lock-in » Cutting-edge quirks » Concurrent Execution Limit is Shared across entire AWS © Rowell Belen 21
  • 24. Enough chit-chat, let's see some code! © Rowell Belen 24
  • 25. Send Events/Metrics to Datadog class DatadogHandler { final rest = new RESTClient('https://app.datadoghq.com/') void handleRequest(Map input, Context context) { def jsonObj = snsJsonBody(input) // Extract Payload def type = jsonObj?.'alert_type' ? 'events' : 'series' def query = ['api_key': System.getenv('DATADOG_API_KEY')] rest.post( path: "api/v1/${type}", body: jsonObj, query: query ) } } © Rowell Belen 25
  • 26. Custom JWT Token Authorizer class AuthorizerHandler { Map handleRequest(Map input, Context context) { // extract token and resource from input def token = input.authorizationToken?.minus('Bearer')?.trim() def resource = input.methodArn // authenticate def claims = verifyToken(token) // return policy createPolicy(claims, resource) } } © Rowell Belen 26
  • 27. Verify Token (cont.) Map verifyToken(final String token) { def algorithm = Algorithm.HMAC256(System.getenv('AUTH0_CLIENT_SECRET')) def verifier = JWT.require(algorithm).build() def decodedJwt = verifier.verify(token) decodedJwt.getClaims() } © Rowell Belen 27
  • 28. Create Security Policy with Claims (cont.) Map createPolicy(final Map claims, final String resource) { [ principalId : claims?.user_id, policyDocument: [ Version : '2012-10-17', Statement: [ Action : 'execute-api:Invoke', Effect : claims ? 'Allow' : 'Deny', Resource: resource ] ], context : claims ] } © Rowell Belen 28
  • 29. How do I invoke a Lambda function programatically? © Rowell Belen 29
  • 30. Direct Lambda Invocation - Define Interfaces interface DocumentAuditService { @LambdaFunction(invocationType = InvocationType.Event, functionName = 'document-audit') void audit(DocumentAudit documentAudit) } class DocumentAudit { String documentId String status } © Rowell Belen 30
  • 31. Direct Lambda Invocation (cont...) - Use a Proxy void handle(Document document, Context context) { // Do something with the document... // Create proxy to DocumentAuditService def docService = LambdaInvokerFactory.builder() .lambdaClient(AWSLambdaClientBuilder.defaultClient()) .build(DocumentAuditService.class) // pass the interface // Call audit lambda function docService.audit( new DocumentAudit(documentId: UUID.randomUUID().toString(), status: 'TRANSMITTED')) } © Rowell Belen 31
  • 32. What is the Serverless Framework? Development toolkit for building, managing and deploying Serverless applications and resources © Rowell Belen 32
  • 33. Serverless Framework CLI npm install serverless -g mkdir my-api && cd my-api serverless create --template aws-groovy-gradle serverless deploy --stage dev serverless invoke --function my-function --log © Rowell Belen 33
  • 34. Available Templates » aws-nodejs » aws-python » aws-groovy-gradle » aws-java-maven » aws-java-gradle » aws-scala-sbt © Rowell Belen 34
  • 35. serverless.yml - Basic Function service: serverless-demo provider: runtime: java8 timeout: 300 memorySize: 1536 package: artifact: /build/dist/serverless-demo.zip functions: my-function: handler: com.bytekast.serverless.MyLambdaFunction::handler © Rowell Belen 35
  • 36. serverless.yml - API Gateway functions: createUser: handler: com.bytekast.serverless.UserService::createUser events: - http: path: users/create method: post deleteUser: handler: com.bytekast.serverless.UserService::deleteUser events: - http: path: users/delete method: delete © Rowell Belen 36
  • 37. serverless.yml - API Gateway (Custom Authorization) ... events: - http: path: users/create method: post cors: true authorizer: arn: arn:aws:lambda:us-east-1:1234567890123:function:authorizer identitySource: method.request.header.Authorization identityValidationExpression: Bearer .* © Rowell Belen 37
  • 38. serverless.yml - SNS Topic Subscription functions: audit: handler: com.bytekast.serverless.AuditService::audit events: - sns: dev-audit-topic © Rowell Belen 38
  • 39. serverless.yml - Scheduled Trigger functions: crawl: handler: com.bytekast.serverless.SearchService::crawl events: - schedule: rate(2 hours) - schedule: cron(0 12 * * ? *) © Rowell Belen 39
  • 40. serverless.yml - IAM Role Permissions provider: ... iamRoleStatements: - Effect: "Allow" Action: - "sqs:*" Resource: arn:aws:sqs:us-east-1:1234567890123:dev-serverless-demo © Rowell Belen 40
  • 41. serverless.yml - Create AWS Resources resources: Resources: InboundQueue: Type: "AWS::SQS::Queue" Properties: QueueName: ${self:provider.stage}-serverless-demo MessageRetentionPeriod: 1209600 VisibilityTimeout: 60 © Rowell Belen 41
  • 42. DEMO Build Slack Command API using Serverless Framework + API Gateway + AWS Lambda https://github.com/bytekast/serverless-demo © Rowell Belen 42
  • 43. What about Cloud Scale DevOps? © Rowell Belen 43
  • 44. Infrastructure and Environment configurations need to be reproducible from a definition under source control © Rowell Belen 44
  • 46. Immutable Infrastructure? Immutable components are replaced for every deployment, rather than being updated in-place © Rowell Belen 46
  • 47. Solution: Lambda Built-In Features » Containers are ephemeral entities that are easily created and destroyed » Preserved history and ability to roll back a bad deployment ( revert to previous version ) » Auto-managed horizontal scaling (Scale out / Scale In) » Automatic Load Balancing » Zero/Minimal Downtime during deployment © Rowell Belen 47
  • 48. Environments should not be connected or otherwise intercommunicate © Rowell Belen 48
  • 49. Solutions: » AWS Lambda supports running functions in different VPCs (dev, stage, prod) » Use separate AWS accounts per Environment © Rowell Belen 49
  • 50. Promote immutable application artifacts from the lowest environment to the highest ( Deployment ) © Rowell Belen 50
  • 51. Solutions: » Publish Versioned Build Artifacts to Repository » Continuous Integration » Continuous Delivery © Rowell Belen 51
  • 53. Metrics » Better Dashboards » Custom Metrics and Events © Rowell Belen 53
  • 54. Other Things to Consider » AWS functions are recycled about every 8 hours » Container instances idle for about 5 minutes are destroyed » Cold starts can cause delay in response times » 50 MB max deployment package size » 5 minute running time limit » 1000 default concurrent function executions across entire AWS account © Rowell Belen 54