Skip to content

aws-cdk-lib/aws_stepfunctions: definitionSubstitutions: element should be an 'object' #21653

@b-c-lucas

Description

@b-c-lucas

Describe the bug

Our codebase was snapped to a now-old version of aws-cdk-lib (2.13.0), but I've been tasked with upgrading our existing code, which has been quite stable since upgrading to CDKv2 many months ago, back on the latest-ish release train for CDKv2.

In attempting to upgrade to latest aws-cdk-lib (2.38.0 at the time of logging this issue), our buildout of state machines within our stack no longer works.

I reviewed changes in the release log, and was able to pin this on a CloudFormation template update for StateMachines as a part of 2.32.0.

Using 2.31.* I don't run into this issue.

Expected Behavior

Upgraded package able to synth CDK stack with Step Functions successfully.

Current Behavior

Traceback (most recent call last):
  ** redacted **
  ...
  File "/home/user/code/src/<redacted>/deploy.py", line 92, in deploy
    app.synth()
  File "/home/user/code/src/.venv/lib/python3.9/site-packages/aws_cdk/__init__.py", line 18253, in synth
    return typing.cast(_CloudAssembly_c693643e, jsii.invoke(self, "synth", [options]))
  File "/home/user/code/src/.venv/lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 148, in wrapped
    return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
  File "/home/user/code/src/.venv/lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 394, in invoke
    return _callback_till_result(self, response, InvokeResponse)
  File "/home/user/code/src/.venv/lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 266, in _callback_till_result
    response = kernel.sync_complete(response.cbid, None, result, response_type)
  File "/home/user/code/src/.venv/lib/python3.9/site-packages/jsii/_kernel/__init__.py", line 432, in sync_complete
    return self.provider.sync_complete(
  File "/home/user/code/src/.venv/lib/python3.9/site-packages/jsii/_kernel/providers/process.py", line 385, in sync_complete
    resp = self._process.send(_CompleteRequest(complete=request), response_type)
  File "/home/user/code/src/.venv/lib/python3.9/site-packages/jsii/_kernel/providers/process.py", line 329, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Resolution error: Supplied properties not correct for "CfnStateMachineProps"
  definitionSubstitutions: element 'KEY_NAME': "key value" should be an 'object'.

Reproduction Steps

This is far from perfect, given this is just a small chunk of a large part of our automation codebase, and this isn't my particular strong suit, but hopefully, this is enough to get the right idea.

import json
from aws_cdk import App, Stack
from aws_cdk.aws_stepfunctions import CfnStateMachine
from constructs import Construct


STATE_MACHINE_TEMPLATE = {
    "StartAt": "Init",
    "States": {
        "Init": {
            "Type": "Pass",
            "Parameters": {
                "FirstName": "${FIRST_NAME}",
            },
            "Next": "Success",
        },
        "Success": {
            "End": True,
            "Type": "Pass",
        },
    },
}

class StateMachineStack(Stack):
    def __init__(self, scope: Construct, id: str):
        super().__init__(scope, id)

        CfnStateMachine(
            self,
            "TheStateMachine",
            definition_string=json.dumps(STATE_MACHINE_TEMPLATE),
            definition_substitutions=dict(FIRST_NAME="Brad"),
        )
        
app = App()
stack = StateMachineStack(scope=app, id="mystatemachine")
app.synth()

Possible Solution

Additional Information/Context

The generated Python CDK code is still valid after updating, so it seems to be purely internal to aws-cdk-lib or the exposed typing needs an update.

CDK CLI Version

2.38.0

Framework Version

No response

Node.js Version

16.16

OS

ubuntu22.04 running via WSL2

Language

Python

Language Version

3.9.13

Other information

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.in-progressThis issue is being actively worked on.package/toolsRelated to AWS CDK Tools or CLI

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions