Stack Creation through Step Function Workflow Execution
Tags: awsstepfunction, s3, cloudformation, iam
Published: 2023-03-05 12:37:26

“ I have to create a stack automatically so I got the way to do it using step function workflow execution. It's very easy to set up using api parameters and cost will be based on the services as s3 and step function.”

AWS Step Functions is a serverless orchestration service that lets you combine AWS Lambda functions and other AWS services to build business-critical applications. Through Step Functions graphical console, you see your application’s workflow as a series of event-driven steps. Step Functions is based on state machines and tasks. A state machine is a workflow. A task is a state in a workflow that represents a single unit of work that another AWS service performs. Each step in a workflow is a state.

In this post, you will get to know how to do stack creation through step function workflow execution. Here I have created s3 bucket, step function and added required permission in the role of step function.

#Prerequisites
You’ll need an Amazon Simple Storage Service for this post. [Getting started with Amazon Simple Storage Service](https://aws.amazon.com/s3/getting-started/) provides instructions on how to create a bucket in simple storage service. For this blog, I assume that I have a s3 bucket created.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vmmwqpx9m1luapkmrx9b.png)
The architecture diagram shows the overall deployment architecture with data flow, aws step function, iam role, cloudformation and s3.

#Solution overview
The blog post consist of the following phases:
1. Create of AWS Step Function with Design Workflow as Cloudformation Create Stack Parameter
2. Output as Cloudformation and S3 Bucket Creation

I have a s3 bucket with required template file as below →
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4u47ynsay4j6lumcsbvo.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iesxurn10vdmcyftq7d7.png)

##Phase 1: Create of AWS Step Function with Design Workflow as Cloudformation Create Stack Parameter
1. Open the AWS Step Function console and create a state machine with default parameters. Create a design workflow as choose of cloudformation create stack for creation of cloudformation and its template service config. Also add the IAM required permission to execute the step function successfully. The api parameter contains cloudformation template url as s3 object url of template stored in s3 and capabilities parameter. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oz1sxd5otzaooen9zhxk.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hdattc69pg4g8ycm32s0.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1tkru0soqwn39z57qe1k.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcsj10dui22v8xl9o7ot.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jjpo0p9nl4yxr8g7k1im.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2qftf01ets1h2gag3idl.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1vgeq3dlx2tbjrp51nji.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/73d1re1jzaekwjgo7kyd.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv88l5d8rg43pehay0fw.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zmx6eo6rzdy16cxxz0ak.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7smjfcccdj173hff22ic.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vwphbpr0qii0ebzyggmz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xkxn9u8ilutevync4ks.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsgs71am8a3v0kw4ei2r.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fpogqlq14yafcib22qps.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1z5bnss5dc95ub9hn3ex.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m7axlol3z4d9gcfbgpxf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0a4qj2um6q1hvpr7ilw4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/veaiexfhcg6w81enj5sx.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iggxbs63bo8bwbueanwj.png)

##Phase 2: Output as Cloudformation and S3 Bucket Creation

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vmml9k7gdfzzthii30av.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3foyyvoa75kawcyi5vv.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zptlgkak8eptpqk0gtrt.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3syseekuuctvcm0gb14.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uuosj2dto8hk4llgv3ij.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ahcqarakky8arj67iqxk.png)

#Clean-up
Delete S3 Bucket, Step Function, Iam Role and Cloudformation Stack.

#Pricing
I review the pricing and estimated cost of this example.

Cost of S3 = $0.91

Cost of Step Functions = $0 for first 4,000 state transitions = $0.0

Total Cost = $0.91

#Summary
In this post, I showed “stack creation through step function workflow execution”.

For more details on AWS Step Functions, Checkout Get started AWS Step Functions, open the [AWS Step Functions console](https://us-east-1.console.aws.amazon.com/states/home?region=us-east-1#/homepage). To learn more, read the [AWS Step Functions documentation](https://docs.aws.amazon.com/step-functions/?id=docs_gateway).

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)