Deploy StepFunctions with CloudFormation, from external definition file

Question:

I’m trying to deploy stepfunctions with CloudFormation, and I’d like to reference the actual stepfunction definition from an external file in S3.

Here’s how the template looks like:

However, this doesn’t seem to be supported, as we are getting error

I am doing something similar for APIs, referencing the actual API definition from an external swagger file, and that seems to be working fine.

Example:

How can I make this work?

Answer:

The trick is to escape the StepFunction DefinitionString property, and include the actual property, DefinitionString, in the external CloudFormation referenced file. Escaping only the stepfunction definition string would fail, CloudFormation complaining that the referenced Transform/Include template, is not a valid yaml/json.
Here’s how it looks like:
Template:

External stepfunction definition file:

Now, although this solves the problem, it’s a bit more difficult to maintain the StepFunction definition, in this form, in source control.

So I’ve thought about using a CloudFormation custom resource backed by a lambda function. The lambda function would deal with the actual StepFunction DefinitionString escaping part.

Here’s how it looks like:
Template:

External StepFunction definition file:

Here’s the documentation for creating AWS Lambda-backed Custom Resources.

There’s still a problem with this.
Transform/Include converts external template boolean properties into string properties.
Therefore, DefinitionString

becomes

CloudFormation then complains about the StepFunction definition not being valid:

Is this a CloudFormation Transform/Include issue? Can someone from AWS give a statement on this?

Leave a Reply