SlideShare a Scribd company logo
1 of 24
Download to read offline
Eric Villa
DevOps Engineer at beSharp
Decompose the monolith
into AWS Step Functions
Serverless On Stage /
Serverless User Group
April 23th, 2019
where the journey began
Noovolari Smart Backup
Noovolari Smart Backup is a SaaS
application designed to backup and recover
your cloud infrastructure through an easy
to use interface.
Key Features:
• Backup of EC2 instances, RDS instances
and RDS Aurora clusters;
• One Click Recovery of EC2 instances,
RDS instances and RDS Aurora clusters;
• File Level Recovery.
First of all, we focused on refactoring One Click Recovery procedures!
Problem: orchestrate each phase of
these long running procedures in a
smart and maintainable way, taking into
account execution state, retries and
rollbacks.
where the journey began
Noovolari Smart Backup
but we could
keep it ins…
Shut up and look
for an orchestration
tool!!!
Who comes to the rescue?
AWS Step Functions
It lets you model complex and long running workflows as state machines.
How does it work?
AWS Step Function are designed using a JSON-based specification language, called
Amazon States Language, that allows you to specify States, Input and Output processing,
Error Handling.
7 types of States available: Task, Wait, Choice, Pass, Succeed, Fail, Parallel.
"TaskState": {
"Type": "Task",
"Resource": <RESOURCE-ARN>,
"Next": "NextState",
"Retry": [
{
"ErrorEquals": [ "ErrorA", "ErrorB" ],
"IntervalSeconds": 1,
"BackoffRate": 2.0,
"MaxAttempts": 2
},
{
"ErrorEquals": [ "ErrorC" ],
"IntervalSeconds": 5
}
],
"Catch": [
{
"ErrorEquals": [ "ErrorA", "ErrorB", "ErrorC" ],
"Next": "RecoveryState"
},
{
"ErrorEquals": [ "States.ALL" ],
"Next": "TerminateMachine"
}
]
}
Input and Output processing Error Handling
State Input and State Output are JSON files.
Task state
A Task state performs work by using an activity or an AWS Lambda function, or by passing
parameters to the API actions of other services.
• fine grained services, relatively simple in complexity;
• high scalability;
• simplified infrastructure management.
We needed something with the following characteristics:
That’s why we opted for AWS Lambda function tasks.
λ function task architecture
Logic layer: it encapsulates
step function's execution state
management and Recovery
business logic.
AWS services access layer: it
encapsulates
AWS SDK for Ruby wrappers,
which provide high-level functions
suitable for Noovolari Smart
Backup needs.
Data access layer: it encapsulates
object-relational mapping,
provided by Ruby’s ActiveRecord
library.
MySQL
Data access
layer
AWS
services
access layer
Logic layer
Access layers
MySQL
Data access
layer
AWS
services
access layer
Logic layer
Instead of duplicating access layers’
code, we decided to create two
Ruby gems (libraries), suitable by
each logic layer.
Each gem is hosted and versioned
on a CodeCommit Git repository.
EC2 instance RDS instance RDS Aurora cluster
recovery logics
AWS services
access gem
Data
access gem
Logic Layer - Step 1
MySQL
Data access
layer
AWS
services
access layer
Logic layer
Extraction of atomic services from the
monolithic recovery procedures.
These atomic services are best suited to
be mapped to AWS Step Functions’ Tasks.
monolithic recovery
procedure
+
+
+
atomic tasks
Logic Layer - Step 2
MySQL
Data access
layer
AWS
services
access layer
Logic layer
Design of a Ruby object that represents the
Step Function’s execution state.
Step Function’s execution state:
• Input
Step Function’s input.
• Context
Data suitable during all the execution,
derived from the input and gathered
from MySQL and MongoDB data
sources.
• State Outputs
They represent the output of lambda
function tasks that compose the
recovery procedure.
• Counters
They represents the # of iterations
reached by a given Waiter (we’ll see it
later).
Logic Layer - Step 3
MySQL
Data access
layer
AWS
services
access layer
Logic layer
Design of a Ruby abstract object that
represents a Task, providing a template that
allows the invocation of a specific service and
the update of the execution state.
Template Method Design Pattern
run() defines the interaction between
invoke_service() and update_state()
methods.
invoke_service() and update_state()
should be implemented for each Task that take
part of the recovery procedure.
Task
+invoke_service()
+update_state()
+run()
ConcreteTask1
+invoke_service()
+update_state()
λ function handler
The handler represents the entry point for the Lambda.
Our handler is responsible to:
1. deserialize step function execution’s state object;
2. instantiate and invoke the right Task object (factory);
3. serialize Task object response and generate λ function output.
to summarize…
"RenameDbInstance": {
"Type": "Task",
"Resource": <LAMBDA_FUNCTION_ARN>,
"Next": “ConfigureRenameDbInstanceCounter",
"Parameters": {
"action": "rename_db_instance",
"data.$": "$.data"
}
}
λ function
handler
Task sw
object
invoke_service()
update_state()
this parameter is necessary to
determine the Task object that
has to be invoked
Orchestration
the music we want the orchestra to play
rename RDS instance
restore RDS instance from snapshot
START
stop original RDS instance
END
Orchestration
the music we want the orchestra to play
rename RDS instance
restore RDS instance from snapshot
START
stop original RDS instance
END
let’s focus on this phase!
Orchestration
Rename RDS instance phase
RenameDbInstance
Task
ConfigureRenameDbInstanceCounter
Task
WasDbInstanceRenamed
Task
CheckWasDbInstanceRenamed
Choice
IncrementRenameDbInstanceCounter
Task
IsRenameDbInstanceCounterLimitReached
Choice
RenameDbInstanceCounterSleep
Wait
no…
no…
yes…
next phase
yes…
CloseSession
Task
‘RenameDbInstance’ status polling
Orchestration
RenameDbInstance task
"RenameDbInstance": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:111111111111:function:bernie-dev-rdsRecovery",
"Next": “ConfigureRenameDbInstanceCounter",
"Parameters": {
"action": "rename_db_instance",
"data.$": "$.data"
},
"Catch": [{
"ErrorEquals": ["States.ALL"],
"Next": "CloseSession",
"ResultPath": "$.error-info"
}]
}
λ function’s input is specified by Parameters.
Catch, together with States.ALL wildcard, allows you to catch any kind of
error and route the State Machine to rollback.
ConfigureRenameDbInstanceCounter, WasDbInstanceRenamed and
IncrementRenameDbInstanceCounter Task states are implemented in the same way.
Orchestration
CheckWasDbInstanceRenamed Choice
"CheckWasDbInstanceRenamed": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.data.state_outputs[0].output",
"BooleanEquals": true,
"Next": "RetrieveDbSnapshotIdentifier"
},
{
"Variable": "$.data.state_outputs[0].output",
"BooleanEquals": false,
"Next": “IncrementRenameDbInstanceCounter"
}
]
}
$.data is the path to the Step Function’s execution state.
Last Task’s output corresponds to the first element of the state_outputs array.
$.data.state_outputs[0].output
BooleanEquals comparison operator is used to route the step function to the next step
given the last boolean output.
Orchestration
RenameDbInstanceCounterSleep Wait
"RenameDbInstanceIteratorSleep": {
"Type": "Wait",
"Seconds": 10,
"Next": "WasDbInstanceRenamed"
}
It delays the state machine from continuing for a time specified by Seconds.
Deploy
what are we going to deploy?
EC2 instance Recovery
Step Function
λ function
RDS instance Recovery RDS Aurora cluster Recovery
AWS Services Access and Data Access λ layer
invokes
pulls in
Step Function
λ function
Step Function
λ function
Deploy
what is a λ layer?
It is a .zip file that contains dependencies which you λ function relies on.
It lets you keep your deployment package small since you only have to
reference dependencies.
λ layers are extracted to the /opt directory in the function execution environment.
Each runtime looks for dependencies in a different path under /opt.
Ruby 2.5.0 runtime looks for dependencies in /opt/ruby/gems/2.5.0
Deploy
Basic λ layer
build from Dockerfile:
docker build . -t nsb-basic-layer:1
Deploy
Serverless template - λ function
Deploy
Serverless template - AWS Step Function
Task
Choice
Sleep
Vielen Dank!
Eric Villa
DevOps Engineer at beSharp

More Related Content

What's hot

AWS Community Day Ireland - Refactoring a serverless app
AWS Community Day Ireland - Refactoring a serverless appAWS Community Day Ireland - Refactoring a serverless app
AWS Community Day Ireland - Refactoring a serverless appHeitor Lessa
 
Build and Deploy Serverless Applications with AWS SAM - SRV316 - Chicago AWS ...
Build and Deploy Serverless Applications with AWS SAM - SRV316 - Chicago AWS ...Build and Deploy Serverless Applications with AWS SAM - SRV316 - Chicago AWS ...
Build and Deploy Serverless Applications with AWS SAM - SRV316 - Chicago AWS ...Amazon Web Services
 
Getting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless ComputingGetting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless ComputingAmazon Web Services
 
AWS Lambda Powertools
AWS Lambda PowertoolsAWS Lambda Powertools
AWS Lambda PowertoolsHeitor Lessa
 
Productionize Serverless Application Building and Deployments with AWS SAM - ...
Productionize Serverless Application Building and Deployments with AWS SAM - ...Productionize Serverless Application Building and Deployments with AWS SAM - ...
Productionize Serverless Application Building and Deployments with AWS SAM - ...Amazon Web Services
 
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...Amazon Web Services
 
初探 AWS 平台上的 Docker 服務
初探 AWS 平台上的 Docker 服務初探 AWS 平台上的 Docker 服務
初探 AWS 平台上的 Docker 服務Amazon Web Services
 
Migrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless PlatformMigrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless PlatformAmazon Web Services
 
Grow and Retain Users with Analytics and Push Notifications
Grow and Retain Users with Analytics and Push NotificationsGrow and Retain Users with Analytics and Push Notifications
Grow and Retain Users with Analytics and Push NotificationsAmazon Web Services
 
Serverless Application Development with SAM
Serverless Application Development with SAMServerless Application Development with SAM
Serverless Application Development with SAMAmazon Web Services
 
How to Use AWS Lambda Layers and Lambda Runtime
How to Use AWS Lambda Layers and Lambda RuntimeHow to Use AWS Lambda Layers and Lambda Runtime
How to Use AWS Lambda Layers and Lambda RuntimeDonnie Prakoso
 
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...Amazon Web Services
 
SRV409 Deep Dive on Microservices and Docker
SRV409 Deep Dive on Microservices and DockerSRV409 Deep Dive on Microservices and Docker
SRV409 Deep Dive on Microservices and DockerAmazon Web Services
 
Building Automated Control Systems for Your AWS Infrastructure
Building Automated Control Systems for Your AWS InfrastructureBuilding Automated Control Systems for Your AWS Infrastructure
Building Automated Control Systems for Your AWS InfrastructureAmazon Web Services
 
Building Serverless Backends with AWS Lambda and Amazon API Gateway
Building Serverless Backends with AWS Lambda and Amazon API GatewayBuilding Serverless Backends with AWS Lambda and Amazon API Gateway
Building Serverless Backends with AWS Lambda and Amazon API GatewayAmazon Web Services
 
Deep dive on Serverless application development
Deep dive on Serverless application developmentDeep dive on Serverless application development
Deep dive on Serverless application developmentAmazon Web Services
 
Getting Started with Docker on AWS
Getting Started with Docker on AWSGetting Started with Docker on AWS
Getting Started with Docker on AWSAmazon Web Services
 

What's hot (20)

AWS Community Day Ireland - Refactoring a serverless app
AWS Community Day Ireland - Refactoring a serverless appAWS Community Day Ireland - Refactoring a serverless app
AWS Community Day Ireland - Refactoring a serverless app
 
Build and Deploy Serverless Applications with AWS SAM - SRV316 - Chicago AWS ...
Build and Deploy Serverless Applications with AWS SAM - SRV316 - Chicago AWS ...Build and Deploy Serverless Applications with AWS SAM - SRV316 - Chicago AWS ...
Build and Deploy Serverless Applications with AWS SAM - SRV316 - Chicago AWS ...
 
Getting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless ComputingGetting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless Computing
 
Intro to AWS Lambda
Intro to AWS Lambda Intro to AWS Lambda
Intro to AWS Lambda
 
Serverless for Developers
Serverless for DevelopersServerless for Developers
Serverless for Developers
 
Python on AWS Lambda
Python on AWS Lambda Python on AWS Lambda
Python on AWS Lambda
 
AWS Lambda Powertools
AWS Lambda PowertoolsAWS Lambda Powertools
AWS Lambda Powertools
 
Productionize Serverless Application Building and Deployments with AWS SAM - ...
Productionize Serverless Application Building and Deployments with AWS SAM - ...Productionize Serverless Application Building and Deployments with AWS SAM - ...
Productionize Serverless Application Building and Deployments with AWS SAM - ...
 
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
Real World Development: Peeling The Onion – Migrating A Monolithic Applicatio...
 
初探 AWS 平台上的 Docker 服務
初探 AWS 平台上的 Docker 服務初探 AWS 平台上的 Docker 服務
初探 AWS 平台上的 Docker 服務
 
Migrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless PlatformMigrating your .NET Applications to the AWS Serverless Platform
Migrating your .NET Applications to the AWS Serverless Platform
 
Grow and Retain Users with Analytics and Push Notifications
Grow and Retain Users with Analytics and Push NotificationsGrow and Retain Users with Analytics and Push Notifications
Grow and Retain Users with Analytics and Push Notifications
 
Serverless Application Development with SAM
Serverless Application Development with SAMServerless Application Development with SAM
Serverless Application Development with SAM
 
How to Use AWS Lambda Layers and Lambda Runtime
How to Use AWS Lambda Layers and Lambda RuntimeHow to Use AWS Lambda Layers and Lambda Runtime
How to Use AWS Lambda Layers and Lambda Runtime
 
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
 
SRV409 Deep Dive on Microservices and Docker
SRV409 Deep Dive on Microservices and DockerSRV409 Deep Dive on Microservices and Docker
SRV409 Deep Dive on Microservices and Docker
 
Building Automated Control Systems for Your AWS Infrastructure
Building Automated Control Systems for Your AWS InfrastructureBuilding Automated Control Systems for Your AWS Infrastructure
Building Automated Control Systems for Your AWS Infrastructure
 
Building Serverless Backends with AWS Lambda and Amazon API Gateway
Building Serverless Backends with AWS Lambda and Amazon API GatewayBuilding Serverless Backends with AWS Lambda and Amazon API Gateway
Building Serverless Backends with AWS Lambda and Amazon API Gateway
 
Deep dive on Serverless application development
Deep dive on Serverless application developmentDeep dive on Serverless application development
Deep dive on Serverless application development
 
Getting Started with Docker on AWS
Getting Started with Docker on AWSGetting Started with Docker on AWS
Getting Started with Docker on AWS
 

Similar to Decompose Monolith into AWS Step Functions Serverless Workflow

Building Distributed Applications with AWS Step Functions
Building Distributed Applications with AWS Step FunctionsBuilding Distributed Applications with AWS Step Functions
Building Distributed Applications with AWS Step FunctionsAmazon Web Services
 
AWS Step Functions - Dev lounge Express Edition.pdf
AWS Step Functions - Dev lounge Express Edition.pdfAWS Step Functions - Dev lounge Express Edition.pdf
AWS Step Functions - Dev lounge Express Edition.pdfAmazon Web Services
 
AWS Summit Singapore - Lambda, Step Functions and Datadog: A Symphony
AWS Summit Singapore - Lambda, Step Functions and Datadog: A SymphonyAWS Summit Singapore - Lambda, Step Functions and Datadog: A Symphony
AWS Summit Singapore - Lambda, Step Functions and Datadog: A SymphonyAmazon Web Services
 
Building Scalable Applications with Laravel
Building Scalable Applications with LaravelBuilding Scalable Applications with Laravel
Building Scalable Applications with LaravelMuhammad Shakeel
 
Nyc big datagenomics-pizarroa-sept2017
Nyc big datagenomics-pizarroa-sept2017Nyc big datagenomics-pizarroa-sept2017
Nyc big datagenomics-pizarroa-sept2017delagoya
 
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션AWS Step Functions을 활용한 서버리스 앱 오케스트레이션
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션Amazon Web Services Korea
 
Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkLuciano Mammino
 
Event Sourcing - what could possibly go wrong?
Event Sourcing - what could possibly go wrong?Event Sourcing - what could possibly go wrong?
Event Sourcing - what could possibly go wrong?Andrzej Ludwikowski
 
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxTrack 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxAmazon Web Services
 
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...Codemotion
 
Serverless Architectural Patterns & Best Practices
Serverless Architectural Patterns & Best PracticesServerless Architectural Patterns & Best Practices
Serverless Architectural Patterns & Best PracticesDaniel Zivkovic
 
NEW LAUNCH! Building Distributed Applications with AWS Step Functions
NEW LAUNCH! Building Distributed Applications with AWS Step FunctionsNEW LAUNCH! Building Distributed Applications with AWS Step Functions
NEW LAUNCH! Building Distributed Applications with AWS Step FunctionsAmazon Web Services
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleRaimonds Simanovskis
 
SMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step FunctionsSMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step FunctionsAmazon Web Services
 
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?SegFaultConf
 
Kubernetes Operators With Scala
Kubernetes Operators With ScalaKubernetes Operators With Scala
Kubernetes Operators With ScalaPeter Barron
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsSebastian Springer
 
AWS re:Invent 2016: From Monolithic to Microservices: Evolving Architecture P...
AWS re:Invent 2016: From Monolithic to Microservices: Evolving Architecture P...AWS re:Invent 2016: From Monolithic to Microservices: Evolving Architecture P...
AWS re:Invent 2016: From Monolithic to Microservices: Evolving Architecture P...Amazon Web Services
 
Using AWS Batch and AWS Step Functions to Design and Run High-Throughput Work...
Using AWS Batch and AWS Step Functions to Design and Run High-Throughput Work...Using AWS Batch and AWS Step Functions to Design and Run High-Throughput Work...
Using AWS Batch and AWS Step Functions to Design and Run High-Throughput Work...Amazon Web Services
 

Similar to Decompose Monolith into AWS Step Functions Serverless Workflow (20)

Building Distributed Applications with AWS Step Functions
Building Distributed Applications with AWS Step FunctionsBuilding Distributed Applications with AWS Step Functions
Building Distributed Applications with AWS Step Functions
 
AWS Step Functions - Dev lounge Express Edition.pdf
AWS Step Functions - Dev lounge Express Edition.pdfAWS Step Functions - Dev lounge Express Edition.pdf
AWS Step Functions - Dev lounge Express Edition.pdf
 
AWS Summit Singapore - Lambda, Step Functions and Datadog: A Symphony
AWS Summit Singapore - Lambda, Step Functions and Datadog: A SymphonyAWS Summit Singapore - Lambda, Step Functions and Datadog: A Symphony
AWS Summit Singapore - Lambda, Step Functions and Datadog: A Symphony
 
Serverless Apps with AWS Step Functions
Serverless Apps with AWS Step FunctionsServerless Apps with AWS Step Functions
Serverless Apps with AWS Step Functions
 
Building Scalable Applications with Laravel
Building Scalable Applications with LaravelBuilding Scalable Applications with Laravel
Building Scalable Applications with Laravel
 
Nyc big datagenomics-pizarroa-sept2017
Nyc big datagenomics-pizarroa-sept2017Nyc big datagenomics-pizarroa-sept2017
Nyc big datagenomics-pizarroa-sept2017
 
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션AWS Step Functions을 활용한 서버리스 앱 오케스트레이션
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션
 
Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless framework
 
Event Sourcing - what could possibly go wrong?
Event Sourcing - what could possibly go wrong?Event Sourcing - what could possibly go wrong?
Event Sourcing - what could possibly go wrong?
 
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptxTrack 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
Track 4 Session 2_MAD03 容器技術和 AWS Lambda 讓您專注「應用優先」.pptx
 
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
Andrzej Ludwikowski - Event Sourcing - what could possibly go wrong? - Codemo...
 
Serverless Architectural Patterns & Best Practices
Serverless Architectural Patterns & Best PracticesServerless Architectural Patterns & Best Practices
Serverless Architectural Patterns & Best Practices
 
NEW LAUNCH! Building Distributed Applications with AWS Step Functions
NEW LAUNCH! Building Distributed Applications with AWS Step FunctionsNEW LAUNCH! Building Distributed Applications with AWS Step Functions
NEW LAUNCH! Building Distributed Applications with AWS Step Functions
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
SMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step FunctionsSMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step Functions
 
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
 
Kubernetes Operators With Scala
Kubernetes Operators With ScalaKubernetes Operators With Scala
Kubernetes Operators With Scala
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.js
 
AWS re:Invent 2016: From Monolithic to Microservices: Evolving Architecture P...
AWS re:Invent 2016: From Monolithic to Microservices: Evolving Architecture P...AWS re:Invent 2016: From Monolithic to Microservices: Evolving Architecture P...
AWS re:Invent 2016: From Monolithic to Microservices: Evolving Architecture P...
 
Using AWS Batch and AWS Step Functions to Design and Run High-Throughput Work...
Using AWS Batch and AWS Step Functions to Design and Run High-Throughput Work...Using AWS Batch and AWS Step Functions to Design and Run High-Throughput Work...
Using AWS Batch and AWS Step Functions to Design and Run High-Throughput Work...
 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

Decompose Monolith into AWS Step Functions Serverless Workflow

  • 1. Eric Villa DevOps Engineer at beSharp Decompose the monolith into AWS Step Functions Serverless On Stage / Serverless User Group April 23th, 2019
  • 2. where the journey began Noovolari Smart Backup Noovolari Smart Backup is a SaaS application designed to backup and recover your cloud infrastructure through an easy to use interface. Key Features: • Backup of EC2 instances, RDS instances and RDS Aurora clusters; • One Click Recovery of EC2 instances, RDS instances and RDS Aurora clusters; • File Level Recovery. First of all, we focused on refactoring One Click Recovery procedures!
  • 3. Problem: orchestrate each phase of these long running procedures in a smart and maintainable way, taking into account execution state, retries and rollbacks. where the journey began Noovolari Smart Backup but we could keep it ins… Shut up and look for an orchestration tool!!!
  • 4. Who comes to the rescue? AWS Step Functions It lets you model complex and long running workflows as state machines.
  • 5. How does it work? AWS Step Function are designed using a JSON-based specification language, called Amazon States Language, that allows you to specify States, Input and Output processing, Error Handling. 7 types of States available: Task, Wait, Choice, Pass, Succeed, Fail, Parallel. "TaskState": { "Type": "Task", "Resource": <RESOURCE-ARN>, "Next": "NextState", "Retry": [ { "ErrorEquals": [ "ErrorA", "ErrorB" ], "IntervalSeconds": 1, "BackoffRate": 2.0, "MaxAttempts": 2 }, { "ErrorEquals": [ "ErrorC" ], "IntervalSeconds": 5 } ], "Catch": [ { "ErrorEquals": [ "ErrorA", "ErrorB", "ErrorC" ], "Next": "RecoveryState" }, { "ErrorEquals": [ "States.ALL" ], "Next": "TerminateMachine" } ] } Input and Output processing Error Handling State Input and State Output are JSON files.
  • 6. Task state A Task state performs work by using an activity or an AWS Lambda function, or by passing parameters to the API actions of other services. • fine grained services, relatively simple in complexity; • high scalability; • simplified infrastructure management. We needed something with the following characteristics: That’s why we opted for AWS Lambda function tasks.
  • 7. λ function task architecture Logic layer: it encapsulates step function's execution state management and Recovery business logic. AWS services access layer: it encapsulates AWS SDK for Ruby wrappers, which provide high-level functions suitable for Noovolari Smart Backup needs. Data access layer: it encapsulates object-relational mapping, provided by Ruby’s ActiveRecord library. MySQL Data access layer AWS services access layer Logic layer
  • 8. Access layers MySQL Data access layer AWS services access layer Logic layer Instead of duplicating access layers’ code, we decided to create two Ruby gems (libraries), suitable by each logic layer. Each gem is hosted and versioned on a CodeCommit Git repository. EC2 instance RDS instance RDS Aurora cluster recovery logics AWS services access gem Data access gem
  • 9. Logic Layer - Step 1 MySQL Data access layer AWS services access layer Logic layer Extraction of atomic services from the monolithic recovery procedures. These atomic services are best suited to be mapped to AWS Step Functions’ Tasks. monolithic recovery procedure + + + atomic tasks
  • 10. Logic Layer - Step 2 MySQL Data access layer AWS services access layer Logic layer Design of a Ruby object that represents the Step Function’s execution state. Step Function’s execution state: • Input Step Function’s input. • Context Data suitable during all the execution, derived from the input and gathered from MySQL and MongoDB data sources. • State Outputs They represent the output of lambda function tasks that compose the recovery procedure. • Counters They represents the # of iterations reached by a given Waiter (we’ll see it later).
  • 11. Logic Layer - Step 3 MySQL Data access layer AWS services access layer Logic layer Design of a Ruby abstract object that represents a Task, providing a template that allows the invocation of a specific service and the update of the execution state. Template Method Design Pattern run() defines the interaction between invoke_service() and update_state() methods. invoke_service() and update_state() should be implemented for each Task that take part of the recovery procedure. Task +invoke_service() +update_state() +run() ConcreteTask1 +invoke_service() +update_state()
  • 12. λ function handler The handler represents the entry point for the Lambda. Our handler is responsible to: 1. deserialize step function execution’s state object; 2. instantiate and invoke the right Task object (factory); 3. serialize Task object response and generate λ function output. to summarize… "RenameDbInstance": { "Type": "Task", "Resource": <LAMBDA_FUNCTION_ARN>, "Next": “ConfigureRenameDbInstanceCounter", "Parameters": { "action": "rename_db_instance", "data.$": "$.data" } } λ function handler Task sw object invoke_service() update_state() this parameter is necessary to determine the Task object that has to be invoked
  • 13. Orchestration the music we want the orchestra to play rename RDS instance restore RDS instance from snapshot START stop original RDS instance END
  • 14. Orchestration the music we want the orchestra to play rename RDS instance restore RDS instance from snapshot START stop original RDS instance END let’s focus on this phase!
  • 15. Orchestration Rename RDS instance phase RenameDbInstance Task ConfigureRenameDbInstanceCounter Task WasDbInstanceRenamed Task CheckWasDbInstanceRenamed Choice IncrementRenameDbInstanceCounter Task IsRenameDbInstanceCounterLimitReached Choice RenameDbInstanceCounterSleep Wait no… no… yes… next phase yes… CloseSession Task ‘RenameDbInstance’ status polling
  • 16. Orchestration RenameDbInstance task "RenameDbInstance": { "Type": "Task", "Resource": "arn:aws:lambda:eu-west-1:111111111111:function:bernie-dev-rdsRecovery", "Next": “ConfigureRenameDbInstanceCounter", "Parameters": { "action": "rename_db_instance", "data.$": "$.data" }, "Catch": [{ "ErrorEquals": ["States.ALL"], "Next": "CloseSession", "ResultPath": "$.error-info" }] } λ function’s input is specified by Parameters. Catch, together with States.ALL wildcard, allows you to catch any kind of error and route the State Machine to rollback. ConfigureRenameDbInstanceCounter, WasDbInstanceRenamed and IncrementRenameDbInstanceCounter Task states are implemented in the same way.
  • 17. Orchestration CheckWasDbInstanceRenamed Choice "CheckWasDbInstanceRenamed": { "Type": "Choice", "Choices": [ { "Variable": "$.data.state_outputs[0].output", "BooleanEquals": true, "Next": "RetrieveDbSnapshotIdentifier" }, { "Variable": "$.data.state_outputs[0].output", "BooleanEquals": false, "Next": “IncrementRenameDbInstanceCounter" } ] } $.data is the path to the Step Function’s execution state. Last Task’s output corresponds to the first element of the state_outputs array. $.data.state_outputs[0].output BooleanEquals comparison operator is used to route the step function to the next step given the last boolean output.
  • 18. Orchestration RenameDbInstanceCounterSleep Wait "RenameDbInstanceIteratorSleep": { "Type": "Wait", "Seconds": 10, "Next": "WasDbInstanceRenamed" } It delays the state machine from continuing for a time specified by Seconds.
  • 19. Deploy what are we going to deploy? EC2 instance Recovery Step Function λ function RDS instance Recovery RDS Aurora cluster Recovery AWS Services Access and Data Access λ layer invokes pulls in Step Function λ function Step Function λ function
  • 20. Deploy what is a λ layer? It is a .zip file that contains dependencies which you λ function relies on. It lets you keep your deployment package small since you only have to reference dependencies. λ layers are extracted to the /opt directory in the function execution environment. Each runtime looks for dependencies in a different path under /opt. Ruby 2.5.0 runtime looks for dependencies in /opt/ruby/gems/2.5.0
  • 21. Deploy Basic λ layer build from Dockerfile: docker build . -t nsb-basic-layer:1
  • 23. Deploy Serverless template - AWS Step Function Task Choice Sleep
  • 24. Vielen Dank! Eric Villa DevOps Engineer at beSharp