From 96581d0f114ea0a25f5ada32d813e167ddc22339 Mon Sep 17 00:00:00 2001 From: MEPalma <64580864+MEPalma@users.noreply.github.com> Date: Mon, 24 Mar 2025 23:09:37 +0100 Subject: [PATCH] pass logging configuration to create and update state machine actions --- .../aws_stepfunctions_statemachine.py | 6 +++ .../resources/test_stepfunctions.py | 28 ++++++++++ .../test_stepfunctions.snapshot.json | 43 +++++++++++++++ .../test_stepfunctions.validation.json | 3 ++ ...emachine_machine_logging_configuration.yml | 52 +++++++++++++++++++ 5 files changed, 132 insertions(+) create mode 100644 tests/aws/templates/statemachine_machine_logging_configuration.yml diff --git a/localstack-core/localstack/services/stepfunctions/resource_providers/aws_stepfunctions_statemachine.py b/localstack-core/localstack/services/stepfunctions/resource_providers/aws_stepfunctions_statemachine.py index e550a43b2fd41..a1dd521ab5d4a 100644 --- a/localstack-core/localstack/services/stepfunctions/resource_providers/aws_stepfunctions_statemachine.py +++ b/localstack-core/localstack/services/stepfunctions/resource_providers/aws_stepfunctions_statemachine.py @@ -110,6 +110,9 @@ def create( "roleArn": model.get("RoleArn"), "type": model.get("StateMachineType", "STANDARD"), } + logging_configuration = model.get("LoggingConfiguration") + if logging_configuration is not None: + params["loggingConfiguration"] = logging_configuration # get definition s3_client = request.aws_client_factory.s3 @@ -221,6 +224,9 @@ def update( "stateMachineArn": model["Arn"], "definition": definition_str, } + logging_configuration = model.get("LoggingConfiguration") + if logging_configuration is not None: + params["loggingConfiguration"] = logging_configuration step_function.update_state_machine(**params) diff --git a/tests/aws/services/cloudformation/resources/test_stepfunctions.py b/tests/aws/services/cloudformation/resources/test_stepfunctions.py index 0925c3aec449b..36b807157c367 100644 --- a/tests/aws/services/cloudformation/resources/test_stepfunctions.py +++ b/tests/aws/services/cloudformation/resources/test_stepfunctions.py @@ -352,3 +352,31 @@ def test_cfn_statemachine_default_s3_location( sfn_snapshot.match( "describe_state_machine_output_on_update", describe_state_machine_output_on_update ) + + +@markers.aws.validated +@markers.snapshot.skip_snapshot_verify( + paths=["$..encryptionConfiguration", "$..tracingConfiguration"] +) +def test_statemachine_create_with_logging_configuration( + 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"), + JsonpathTransformer("$..logGroupArn", "log-group-arn"), + ] + ) + stack = deploy_cfn_template( + template_path=os.path.join( + os.path.dirname(__file__), + "../../../templates/statemachine_machine_logging_configuration.yml", + ) + ) + statemachine_arn = stack.outputs["StateMachineArnOutput"] + describe_state_machine_result = aws_client.stepfunctions.describe_state_machine( + stateMachineArn=statemachine_arn + ) + sfn_snapshot.match("describe_state_machine_result", describe_state_machine_result) diff --git a/tests/aws/services/cloudformation/resources/test_stepfunctions.snapshot.json b/tests/aws/services/cloudformation/resources/test_stepfunctions.snapshot.json index df07ef28a658a..0a71d3489d9ce 100644 --- a/tests/aws/services/cloudformation/resources/test_stepfunctions.snapshot.json +++ b/tests/aws/services/cloudformation/resources/test_stepfunctions.snapshot.json @@ -66,5 +66,48 @@ } } } + }, + "tests/aws/services/cloudformation/resources/test_stepfunctions.py::test_statemachine_create_with_logging_configuration": { + "recorded-date": "24-03-2025, 21:58:55", + "recorded-content": { + "describe_state_machine_result": { + "creationDate": "datetime", + "definition": { + "StartAt": "S0", + "States": { + "S0": { + "Type": "Pass", + "End": true + } + } + }, + "encryptionConfiguration": { + "type": "AWS_OWNED_KEY" + }, + "loggingConfiguration": { + "destinations": [ + { + "cloudWatchLogsLogGroup": { + "logGroupArn": "" + } + } + ], + "includeExecutionData": true, + "level": "ALL" + }, + "name": "", + "roleArn": "", + "stateMachineArn": "", + "status": "ACTIVE", + "tracingConfiguration": { + "enabled": false + }, + "type": "STANDARD", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } } } diff --git a/tests/aws/services/cloudformation/resources/test_stepfunctions.validation.json b/tests/aws/services/cloudformation/resources/test_stepfunctions.validation.json index bfd2fc0768091..7c3fd62726991 100644 --- a/tests/aws/services/cloudformation/resources/test_stepfunctions.validation.json +++ b/tests/aws/services/cloudformation/resources/test_stepfunctions.validation.json @@ -1,5 +1,8 @@ { "tests/aws/services/cloudformation/resources/test_stepfunctions.py::test_cfn_statemachine_default_s3_location": { "last_validated_date": "2024-12-17T16:06:46+00:00" + }, + "tests/aws/services/cloudformation/resources/test_stepfunctions.py::test_statemachine_create_with_logging_configuration": { + "last_validated_date": "2025-03-24T21:58:55+00:00" } } diff --git a/tests/aws/templates/statemachine_machine_logging_configuration.yml b/tests/aws/templates/statemachine_machine_logging_configuration.yml new file mode 100644 index 0000000000000..10694785acccb --- /dev/null +++ b/tests/aws/templates/statemachine_machine_logging_configuration.yml @@ -0,0 +1,52 @@ +AWSTemplateFormatVersion: '2010-09-09' + +Resources: + StateMachineRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: '2012-10-17' + Statement: + - Effect: Allow + Principal: + Service: states.amazonaws.com + Action: sts:AssumeRole + Policies: + - PolicyName: StateMachineFullAccess + PolicyDocument: + Version: '2012-10-17' + Statement: + - Effect: Allow + Action: "*" + Resource: "*" + + LogGroup: + Type: AWS::Logs::LogGroup + Properties: + RetentionInDays: 14 + + StateMachine: + Type: AWS::StepFunctions::StateMachine + Properties: + StateMachineType: STANDARD + RoleArn: !GetAtt StateMachineRole.Arn + DefinitionString: | + { + "StartAt": "S0", + "States": { + "S0": { + "Type": "Pass", + "End": true + } + } + } + LoggingConfiguration: + Destinations: + - CloudWatchLogsLogGroup: + LogGroupArn: !GetAtt LogGroup.Arn + IncludeExecutionData: true + Level: ALL + +Outputs: + StateMachineArnOutput: + Value: !Ref StateMachine