Enable Logging in State Machine Using CloudFormation

Gargee Bhatnagar
4 min readFeb 18, 2023

“ I have checked the documents of AWS to enable logging in state machine using cloudformation. It’s easy to enable the log feature using cloudformation. The Pricing is based on services usage.”

AWS CloudFormation is a service that helps you model and set up your AWS resources so that you can speed less time managing those resources and more time focusing on your applications that run in AWS. You create a template that describes all the AWS resources that you want (like Amazon EC2 instances or Amazon RDS DB instances), and CloudFormation takes care of provisioning and configuring those resources for you.

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 experience to enable logging in state machine using cloudformation. Here I have created a step function (a state machine) from cloudformation with a lambda function invoke. Also added cf parameter for logging feature in template.

Prerequisites

You’ll need an AWS Lambda for this post. Getting started with aws Lambda provides instructions on how to create a lambda function. For this blog, I assume that I have a lambda function created.

Architecture Overview

The architecture diagram shows the overall deployment architecture with data flow, s3, cloudformation, lambda, cloudwatch, step function.

Solution overview

The blog post consists of the following phases:

  1. Create of S3 Bucket and Upload of Step Function Json File
  2. Create of Cloudformation Stack for Step Function with Logging Feature Enabled and Lambda Function Invoke from S3 URI

I have a lambda function as below →

Phase 1: Create of S3 Bucket and Upload of Step Function Json File

  1. Open the s3 console and create a bucket with default settings. Add a json file in it which contains lambda function arn to invoke it in step function.

Phase 2: Create of Cloudformation Stack for Step Function with Logging Feature Enabled and Lambda Function Invoke from S3 URI

  1. Open the cloudformation console and create a stack for step function with lambda function invoke.

Clean-up

Delete CloudFormation Stack, S3 Bucket and Lambda Function.

Pricing

I review the pricing and estimated cost of this example.

Cost of CloudWatch = $0.0

Cost of Lambda = $0.0

Cost of Simple Storage Service = $1.0

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

Total Cost = $(0.0 + 0.0 + 1.0 + 0.0) = $1.0

Summary

In this post, I showed “how to enable logging in state machine using cloudformation”.

For more details on AWS CloudFormation, Checkout Get started AWS CloudFormation, open the AWS CloudFormation console. To learn more, read the AWS CloudFormation documentation.

For more details on AWS Step Functions, Checkout Get started AWS Step Functions, open the AWS Step Functions console. To learn more, read the AWS Step Functions documentation.

Thanks for reading!

Connect with me: Linkedin

--

--

Gargee Bhatnagar

DevOps Engineer and AWS Solution Architect in Electromech Corporation