Skip to content

CloudFormation, Fix Retrieval of State Machine Definitions On Stack Update #12044

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ def update(
if not model.get("Arn"):
model["Arn"] = request.previous_state["Arn"]

definition_str = self._get_definition(model, request.aws_client_factory.s3)
params = {
"stateMachineArn": model["Arn"],
"definition": model["DefinitionString"],
"definition": definition_str,
}

step_function.update_state_machine(**params)
Expand Down
71 changes: 71 additions & 0 deletions tests/aws/services/cloudformation/resources/test_stepfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import urllib.parse

import pytest
from localstack_snapshot.snapshots.transformer import JsonpathTransformer

from localstack import config
from localstack.testing.pytest import markers
Expand Down Expand Up @@ -281,3 +282,73 @@ def test_cfn_statemachine_with_dependencies(deploy_cfn_template, aws_client):
statemachines = [sm for sm in rs["stateMachines"] if sm_name in sm["name"]]

assert not statemachines


@markers.aws.validated
@markers.snapshot.skip_snapshot_verify(
paths=["$..encryptionConfiguration", "$..tracingConfiguration"]
)
def test_cfn_statemachine_default_s3_location(
s3_create_bucket, deploy_cfn_template, aws_client, sfn_snapshot
):
sfn_snapshot.add_transformers_list(
[
JsonpathTransformer("$..roleArn", "role-arn"),
JsonpathTransformer("$..stateMachineArn", "state-machine-arn"),
JsonpathTransformer("$..name", "state-machine-name"),
]
)
cfn_template_path = os.path.join(
os.path.dirname(__file__),
"../../../templates/statemachine_machine_default_s3_location.yml",
)

stack_name = f"test-cfn-statemachine-default-s3-location-{short_uid()}"

file_key = f"file-key-{short_uid()}.json"
bucket_name = s3_create_bucket()
state_machine_template = {
"Comment": "step: on create",
"StartAt": "S0",
"States": {"S0": {"Type": "Succeed"}},
}

aws_client.s3.put_object(
Bucket=bucket_name, Key=file_key, Body=json.dumps(state_machine_template)
)

stack = deploy_cfn_template(
stack_name=stack_name,
template_path=cfn_template_path,
max_wait=150,
parameters={"BucketName": bucket_name, "ObjectKey": file_key},
)

stack_outputs = stack.outputs
statemachine_arn = stack_outputs["StateMachineArnOutput"]

describe_state_machine_output_on_create = aws_client.stepfunctions.describe_state_machine(
stateMachineArn=statemachine_arn
)
sfn_snapshot.match(
"describe_state_machine_output_on_create", describe_state_machine_output_on_create
)

file_key = f"2-{file_key}"
state_machine_template["Comment"] = "step: on update"
aws_client.s3.put_object(
Bucket=bucket_name, Key=file_key, Body=json.dumps(state_machine_template)
)
deploy_cfn_template(
stack_name=stack_name,
template_path=cfn_template_path,
is_update=True,
parameters={"BucketName": bucket_name, "ObjectKey": file_key},
)

describe_state_machine_output_on_update = aws_client.stepfunctions.describe_state_machine(
stateMachineArn=statemachine_arn
)
sfn_snapshot.match(
"describe_state_machine_output_on_update", describe_state_machine_output_on_update
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"tests/aws/services/cloudformation/resources/test_stepfunctions.py::test_cfn_statemachine_default_s3_location": {
"recorded-date": "17-12-2024, 16:06:46",
"recorded-content": {
"describe_state_machine_output_on_create": {
"creationDate": "datetime",
"definition": {
"Comment": "step: on create",
"StartAt": "S0",
"States": {
"S0": {
"Type": "Succeed"
}
}
},
"encryptionConfiguration": {
"type": "AWS_OWNED_KEY"
},
"loggingConfiguration": {
"includeExecutionData": false,
"level": "OFF"
},
"name": "<state-machine-name:1>",
"roleArn": "<role-arn:1>",
"stateMachineArn": "<state-machine-arn:1>",
"status": "ACTIVE",
"tracingConfiguration": {
"enabled": false
},
"type": "STANDARD",
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 200
}
},
"describe_state_machine_output_on_update": {
"creationDate": "datetime",
"definition": {
"Comment": "step: on update",
"StartAt": "S0",
"States": {
"S0": {
"Type": "Succeed"
}
}
},
"encryptionConfiguration": {
"type": "AWS_OWNED_KEY"
},
"loggingConfiguration": {
"includeExecutionData": false,
"level": "OFF"
},
"name": "<state-machine-name:1>",
"revisionId": "<uuid:1>",
"roleArn": "<role-arn:1>",
"stateMachineArn": "<state-machine-arn:1>",
"status": "ACTIVE",
"tracingConfiguration": {
"enabled": false
},
"type": "STANDARD",
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 200
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tests/aws/services/cloudformation/resources/test_stepfunctions.py::test_cfn_statemachine_default_s3_location": {
"last_validated_date": "2024-12-17T16:06:46+00:00"
}
}
33 changes: 33 additions & 0 deletions tests/aws/templates/statemachine_machine_default_s3_location.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
AWSTemplateFormatVersion: '2010-09-09'

Parameters:
BucketName:
Type: String

ObjectKey:
Type: String

Resources:
StateMachineRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: states.amazonaws.com
Action: sts:AssumeRole

StateMachine:
Type: AWS::StepFunctions::StateMachine
Properties:
StateMachineType: STANDARD
RoleArn: !GetAtt StateMachineRole.Arn
DefinitionS3Location:
Bucket: !Ref BucketName
Key: !Ref ObjectKey

Outputs:
StateMachineArnOutput:
Value: !Ref StateMachine
Loading