Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

aws-stepfunctions: CDK doesn't realize that it has to destroy the StateMachine if StateMachineType changes #30709

Open
garysassano opened this issue Jun 29, 2024 · 3 comments
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. p3

Comments

@garysassano
Copy link

Describe the bug

1:51:23 AM | UPDATE_FAILED        | AWS::StepFunctions::StateMachine | SfnStateMachineCF6AB1C9
CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename arn:aws:states:eu-central-1:XXXXXXXXXXXX:stateMachine:sfn-state-machine and update the stack again.

CDK attempts to update the state machine when you switch from StateMachineType.STANDARD to StateMachineType.EXPRESS, which is not allowed. As per the official docs:

image

CDK should instead destroy the state machine and recreate it.

Expected Behavior

StateMachine to be destroyed and recreated when StateMachineType changes.

Current Behavior

CDK attempts to update in place the existing StateMachine.

Reproduction Steps

Deploy a StateMachine, change the StateMachineType and try to deploy it again.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.145.0

Framework Version

No response

Node.js Version

20.15.0

OS

Ubuntu 22.04.3 LTS

Language

TypeScript

Language Version

No response

Other information

No response

@garysassano garysassano added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 29, 2024
@github-actions github-actions bot added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Jun 29, 2024
@khushail khushail added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Jul 1, 2024
@khushail khushail self-assigned this Jul 1, 2024
@khushail khushail removed the needs-triage This issue or PR still needs to be triaged. label Jul 1, 2024
@khushail
Copy link
Contributor

khushail commented Jul 1, 2024

Hi @garysassano , thanks for reaching out.

IMO, as its clearly mentioned in the docs that StateMachineType can not be changed, I assume that's an acceptable behavior.

AFAIK, Since the StateMachineArn is not mutable, changing the StateMachineType is causing a replacement and hence the error. I am not really sure why you would want to do that.

It would be advisable to create a new StateMachine if type is changed. I am not clear on the usecase of changing the type when new one can be created. Could you please clarify?

See this as well -

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-statemachinename

Screenshot 2024-07-01 at 3 27 22 PM

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Jul 1, 2024
@pahud
Copy link
Contributor

pahud commented Jul 1, 2024

StateMachineType is a prop of AWS::StepFunctions::StateMachine so it's definitely allowed to change from CFN's perspective.

But we need to note:

Update requires: Replacement

This means a new StateMachine would be created in replacement of the previous one.

One common error is that when you have specified a custom name of the original one, creating a new one with exactly the same name as a replacement of the original one would cause duplication if the resource does not allow you to have duplicate name as the error indicates:

CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename arn:aws:states:eu-central-1:XXXXXXXXXXXX:stateMachine:sfn-state-machine and update the stack again.

Solution:

  1. Do not specify stateMachineName, instead, let CFN auto generate for you.
  2. If it doesn't work, you need to specify a different custom name when you update the StateMachineType.

Let me know if it works for you.

@pahud
Copy link
Contributor

pahud commented Jul 1, 2024

PoC

    // create a dummy statemachine
    new sfn.StateMachine(this, 'StateMachine', {
      definition: new sfn.Pass(this, 'Pass'),
      stateMachineType: StateMachineType.EXPRESS, // update this and re-deploy
    });

cdk diff

image

and cdk deploy works with no error.

image

@pahud pahud added the p3 label Jul 1, 2024
@khushail khushail removed their assignment Jul 1, 2024
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 2, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions bug This issue is a bug. p3
Projects
None yet
Development

No branches or pull requests

3 participants