-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
When using CloudFormation or CDK to deploy a Step Functions state machine, it is not possible to update the CloudFormation stack because the DefinitionS3Location
directive is not supported by the Step Functions CloudFormation plugin.
When I run cdklocal deploy
for the second time, I see the error:
localstack-main | 2024-07-23T22:07:40.792 WARN --- [-functhread6] l.s.c.deployment_utils : Unexpected error processing resource type AWS::StepFunctions::StateMachine: Exception: 'DefinitionString' - {'Name': 'StateMachineName', 'RoleArn': 'arn:aws:iam::000000000000:role/Admin', 'DefinitionS3Location': {'Bucket': 'assets', 'Key': 'state-machine-2.asl.json'}, 'Arn': 'arn:aws:states:us-east-1:000000000000:stateMachine:Buggy-StateMachine-8c880a39'} - status: None
The state machine definition is not correctly updated.
Expected Behavior
A second (or successive) cdklocal deploy
should update the state machine correctly without crashing.
How are you starting LocalStack?
With a docker-compose file
Steps To Reproduce
How are you starting localstack (e.g., bin/localstack
command, arguments, or docker-compose.yml
)
docker-compose up
Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)
awslocal s3 mb s3://assets
awslocal s3 cp state-machine-1.asl.json s3://assets/state-machine-1.asl.json
awslocal s3 cp state-machine-2.asl.json s3://assets/state-machine-2.asl.json
awslocal cloudformation create-stack --stack-name Buggy --template-body file://cloudformation-1.json
The failure happens when executing this command:
awslocal cloudformation update-stack --stack-name Buggy --template-body file://cloudformation-2.json
Where state-machine-N.asl.json
is:
{
"StartAt": "SuccessN", # set N to 1 or 2
"States": {
"SuccessN": {
"Type": "Succeed"
}
}
}
and cloudformation-N.json
is:
"Resources": {
"StateMachine": {
"Type": "AWS::StepFunctions::StateMachine",
"Properties": {
"Name": "StateMachineName",
"RoleArn": "arn:aws:iam::000000000000:role/Admin",
"DefinitionS3Location": {
"Bucket": "assets",
"Key": "state-machine-N.asl.json". # set N to 1 or 2
}
}
}
}
}
Environment
- OS: MacOS Sonoma 14.5
- LocalStack:
LocalStack version: 3.5.1.dev
LocalStack Docker image sha: (latest changes from GitHub)
LocalStack build date: 2024-07-23
LocalStack build git hash: a0a1ba090
Anything else?
The following fix works for me. In localstack-core/localstack/services/stepfunctions/resource_providers/aws_stepfunctions_statemachine.py
:
def update(
self,
request: ResourceRequest[StepFunctionsStateMachineProperties],
) -> ProgressEvent[StepFunctionsStateMachineProperties]:
"""
Update a resource
IAM permissions required:
- states:UpdateStateMachine
- states:TagResource
- states:UntagResource
- states:ListTagsForResource
- iam:PassRole
"""
model = request.desired_state
step_function = request.aws_client_factory.stepfunctions
if not model.get("Arn"):
model["Arn"] = request.previous_state["Arn"]
s3_client = request.aws_client_factory.s3
definition_str = self._get_definition(model, s3_client)
params = {
"stateMachineArn": model["Arn"],
"definition": definition_str,
}
The big challenge is writing tests, which I haven't done yet, so this is a bug report rather than a PR.