Hello, Cloud Gurus and welcome to AWS service spotlight. In this series,
we put the spotlight on specific AWS services,
walking through detailed technical demos to explore their features, benefits,
and costs I'm Errol.
And today we're going to talk about AWS step functions.
As our business needs evolve.
There's growing demand for us to creatively approach those needs in a way that's
both cost effective for our businesses while still effective for our consumers.
We serve for this case.
Many engineers rely on the power of serverless architectures and
functions to provide resilience in their applications And microservice
solutions.
More specifically engineering teams are turning away from the monolith
architectures, which are difficult to manage, support and upgrade.
And they're moving towards breaking the application into smaller,
more manageable pieces,
which can be easily changed without large impact to the overall process.
A great example of this use case is AWS Lambda,
which is a great option for small repeatable tasks,
which we can complete within a given run time and memory constraints. However,
the challenge introduced with Lambdas is that very much like containers,
they don't maintain state persistence or error handling once its
runtime has completed. Additionally,
once the application requires more than a couple Lambdas,
its complexity grows exponentially and supporting the application becomes a
daunting task. This is where AWS step functions comes into play.
Initially announced at reinvent 2016,
AWS step functions makes it easy to build complex applications by
connecting and orchestrating multiple smaller microservices
through step functions.
You can configure multiple serverless functions in a series of steps,
as well as combine the use of multiple AWS services into business critical
applications through the creation of state machines.
During this episode,
I'll give a rundown of AWS step functions with an overview of the service.
We'll take a look at its features and costs,
and I'll run you through a demo showing you how step function works before
giving my final verdict of the service itself. So if you're ready,
let's get started.
Now let's talk about the service AWS step functions is a serverless function
orchestration service,
which easily allows you to sequence multiple AWS Lambda functions
or other services.
And so larger business applications through the creation of workflows.
Using this service,
you can join loosely coupled application components into larger business
solutions, creating what's called state machines.
AWS step functions allows you to easily configure state
machines or workflows using Amazon's state language.
And I know what you're thinking. I'll have to learn another language.
No worries about that.
Amazon state language is a proprietary AWS language,
which is very close to JSON or JavaScript object notation
within your state machine. You can define various States.
Now States refer to the status of a task or a service.
The States are used as triggers for your workflow and can be used
to begin, pause, complete or completely terminated task.
Now step functions also natively integrates with multiple AWS
services, including compute services like AWS Lambda,
ECS, EKS, Kubernetes service, and AWS far gate,
database services, including dynamo DB messaging,
including simple notification as well as Queues,
API gateway and more step functions makes it fast and easy
to introduce these services to your state machine by providing Amazon state
language code snippets,
which will help you reduce your development time and get your micro service off
the ground. In no time.
Step functions provide a great visual interface,
which outlines checkpoints as well as event driven workflow within the
application.
This makes monitoring and troubleshooting the workflow easy.
Since you can see the progress of each step of the application.
Step function also provides two kinds of workflows to meet your
application needs - a standard workflow as well as express workflows
standard or the default workflow allows for a minimum duration of
one year.
And are ideal for long running durable and auditable workflows while
express workflows expects the workflow to be completed in five
minutes and possibly include synchronous as well as asynchronous
workflows.
Express workflows are ideal for high volume event
processing workloads, such as internet of things, data ingestion,
streaming, data processing,
and transformation and mobile application backends.
Also through the configuration of workflows.
Step functions allows you to manage application parallelization
sequencing, error handling, and retry logic as well as state.
The parallelization feature is great for reducing the right time of long running
processes.
This functionality also makes it easy for States to pass data to
other States and microservices,
to handle exceptions at time,
make decisions as well as execute multiple paths in parallel and more
and last but not least AWS step functions has a budget friendly pricing
model,
which is pay-per-use with a low cost price for state transitions and
workflow duration, which brings us to our next point cost.
Now let's talk about AWS step functions's pricing model.
Like most of the AWS services offered pricing can be a little bit
complicated for AWS step functions.
There are multiple factors that plays in to how you are charged for your use of
the service.
First you're charged based on the type of workflow you use either standard or
express as well as the number of state transitions and the duration of the
workflow. Luckily with this service,
you're charged minimally for each state transition and the duration of the
workflow.
So you'll have to run thousands of workflows for several hours before you
notice any impact to your bill. However, auxiliary services such as compute,
database, messaging and more will incur their own charges.
Here's what you need to know about AWS Step functions Pricing. First,
let's talk about standard workflows.
With standard workflows You're only charged for the number of state transitions.
Step functions,
count state transitions Each time a step of your workflow is
executed.
You are charged for the total number of state transitions across all of your
machines, including retries. For example,
from one Lambda execution to another will count as one state transition,
a retry would count as another.
Luckily for smaller applications and newcomers desiring to get their hands dirty
with AWS step functions The free tier includes 4,000 state
transitions per month. After 4,000 state transitions,
AWS charges you two and a half cent per thousand state
transitions thereafter. Now let's talk about express workflows.
With express workflows You're charged for both the number of state transitions,
as well as the duration of the workflow.
You basically are charged $1 per million request.
Duration is calculated from the time your workflow begins
executing until it completes or otherwise terminates,
rounded up to the nearest hundred milliseconds.
And the amount of memory used in the execution of your workflow billed
in 64 megabyte chunks.
Duration is currently charged at 6 cent per gigabyte hours.
Now let's head to the demo and check out step functions.
Hello and welcome to this demo on AWS step functions in today's
demo, we'll build a small step function workflow,
which checks the price of Bitcoin.
And then that buys us on whether we should buy more or sell based on its
current price.
To get started We'll head over to the service by typing step functions here on
the AWS management console search bar,
we'll click the service. And now we're here on the main splash page,
which gives us some more information on how the service works.
Some of its benefits and features as well as its use cases.
So I'll expand the pane to the left and I'll head over to state machines.
And here on the state machine page is where I'll define my workflow by creating
a state machine. So I'll click create state machine.
And here we can see that there are several ways which AWS gives us to define our
state machine. One way,
will be to author our workflow using code snippets of the Amazon state language,
the proprietary language here use for step functions.
And this option we can define whether we would like a standard workflow or an
express workflow.
We also have options to modify the code definition as well as see how
those options change our visual workflow here. Another way,
which is really useful for those who may be interested in using step functions
for the first time is to run a sample project by selecting any of the
sample projects. For example, make a call to API gateway.
We can see here that we're given a definition and that we can also see how that
definition works as well.
And the final option would be to start with the template.
By starting with the template We're given some simple suggestions from AWS,
which we can later modify our state language based on the template
provided. For this example,
let's select the hello world template and we'll simply leave our standard
workflow here. And then we'll click next.
Let's name our state machine here, Bitcoin pricing.
And for this particular example,
I'd like to create a new role and then I'll click create state
machine. And here we see that our state machine has been successfully created.
So if I go over to the definition, scroll down,
I can see my Amazon state language here with the hello,
starting at hello. There's my hello.
I can see the next is up as the world function,
which is also a pass and I can see the world function there.
So now I'd like to substitute this hello portion of the example with the
Lambda that I've already created,
that calls out to an API and checks the price of Bitcoin.
So I'll do that by going to the top of the page here and clicking edit,
and here under definition, I'll click the drop down to generate a code snippet.
And the first election I have here is the AWS lambda invoke a function which
I'll select.
And this option opens up the Lambda invoke task date,
where I can select the options for my Lambda.
The first thing I'd like to know here is that I'm selecting the function from a
list and then the next dropdown I'd select my Bitcoin pricing
prod Lambda.
I'll keep the payload the same as there's no payload required for this function.
And then I'll just click copy to clipboard.
Now our code snippet has been copied to the clipboard.
I need to rearrange my definition to include the Lambda in which we just
created a task state for.
So there's a couple of steps that I need to do here.
As we look at the state language, we see that the state starts hello,
and after hello, we pass on to world.
So what I need to do is highlight this particular section,
hello and paste What I have from my clipboard here.
Now there's a couple more steps. First.
I'll need to start by telling my state machine where to start now,
which is now our Bitcoin pricing Lambda.
And it's a really good idea to name the step based on the action that it will be
taking.
So I'll just name this Check Bitcoin
pricing. And I'll copy this.
So rename my state here, which is initially invoke Lambda function.
And after this is completed,
I need to check line 14 and tell the state machine what to do
next. And in this case, while we'll change this in just a moment,
to fix our error here, we need to change this to world. And as you can see,
almost instantaneously, our visualization has updated.
And now we see our start.
We see we go into our check Bitcoin pricing lambda followed by world
and end. So I'll click save. I'll ignore my
IAM role permissions as I'll fix that on the back end in just a moment,
click save anyway, and we've updated our state machine.
Now that we've added one step to our hello world state machine.
I've went ahead and added multiple steps to the Amazon state language,
which I'll paste here in the definition box.
So we could get a better understanding of how a longer process would work with
step functions. So as you can see,
I've added multiple steps using another integration that exists within my
current step functions within the AWS account.
So I'll go ahead and click save. I'll save any way.
And now I'll go back to my Bitcoin pricing step function.
Now let's execute our state machine so we can see how the process
works step by step. So I'll click start execution,
no need to change any of the input here.
And now we can see that our state machine is underway.
And as we can notice that after every successful step,
we'll see that the step it turns green. So here on our check Bitcoin pricing,
if we go over to step output, we can see that currently the price of Bitcoin is
57,754.
Let's click the next step to see what's our buy sell recommendation.
We can see that at that particular price,
our Lambda recommended that we sell. I'll scroll down a bit
and now we can see that the process is continuing.
So we're currently waiting on the step, which requests human approval,
which received the stock price, as well as the recommendation type.
We'll go to the next step,
which generates the buy or sell in which this case,
the state machine has decided to sell the stock.
So here we see the id of the run, the price, the type,
which is sell at a quantity of one and a timestamp. And then at the end here,
we are reporting out more results.
So our process has successfully completed.
And the really cool thing here about step functions here at the bottom is that
you have an execution event history where you can both access
easily, the Lambda, as well as the CloudWatch logs,
as well as view the history of where the step may have failed or successfully
completed. So that concludes this demo on AWS step functions.
So what's the verdict.
Let's briefly discuss the pros and cons of AWS step functions.
We'll start with the pros.
First off AWS step functions is all things serverless,
meaning we don't have to manage infrastructure to create these workflows,
managing the running of our source code.
AWS step functions also allows you to easily create complex
workflows across multiple AWS services.
Due to its statefullness It easily manages States without the use of
messaging queues and databases.
Also another plus of using this service is it's parallelization,
which allows us to shorten the run time of our long running processes.
Lastly, step functions provide a great visualization interface,
which is easy to follow for the technical and untechnical alike.
Now let's talk about the cons.
One of the few drawbacks of learning AWS step functions is that you
must come to a pretty good understanding of Amazon state language,
which is the proprietary AWS language used for step functions.
Also, there is a learning curve for learning to programmatically integrate other
services within the workflow. Lastly,
one con of using this service is that defining too much business logic within
the service or your state machine creates vendor lock-in so should you
invest, evaluate or revisit.
[Inaudible]. My recommendation.
Is to invest. AWS Step function is a great orchestration tool,
which allows us to seamlessly couple our microservice and loosely coupled
application components into a single unified workflow.
If you're currently supporting a monolith application,
which is difficult to support and upgrade using a service like step functions
would be great in reducing complexity through simplifying your
architecture into smaller microservices and creating a visual
workflow to monitor the smaller steps of the process as they are occurring.
Additionally, AWS step functions are useful for data processing,
ensuring that long running jobs execute an order and complete successfully.
It's also a great service for automating recurring tasks,
such as patch management, infrastructure selection,
and data synchronization,
and step functions will automatically scale and respond to timeouts
as well as retry fail tasks.
This service is also great for those applications,
which require human interaction within a larger workflow.
From a programmatic perspective because AWS step functions, native languages,
Amazon statement, which, which is very similar to JSON,
it makes use of this service very easy and the technical barrier of
entry for this service, somewhat low.
Step functions also make kicking off workflows very easy for those
less technical business users who support processes and needs to kick them
off at any time.
So that's it for this episode of AWS service spotlight keep being awesome
cloud gurus, and I hope to see you next time on AWS service spotlight.