diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index b897a67867..77dcafcb30 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -1120,7 +1120,8 @@ class SamStateMachine(SamResourceMacro): "Name": PropertyType(False, is_str()), "Type": PropertyType(False, is_str()), "Tags": PropertyType(False, is_type(dict)), - "Policies": PropertyType(False, one_of(is_str(), is_type(dict), list_of(one_of(is_str(), is_type(dict))))), + "Policies": PropertyType(False, one_of(is_str(), list_of(one_of(is_str(), is_type(dict), is_type(dict))))), + "Tracing": PropertyType(False, is_type(dict)), } event_resolver = ResourceTypeResolver(samtranslator.model.stepfunctions.events,) @@ -1142,6 +1143,7 @@ def to_cloudformation(self, **kwargs): definition_substitutions=self.DefinitionSubstitutions, role=self.Role, state_machine_type=self.Type, + tracing=self.Tracing, events=self.Events, event_resources=event_resources, event_resolver=self.event_resolver, diff --git a/samtranslator/model/stepfunctions/generators.py b/samtranslator/model/stepfunctions/generators.py index 42e172b45f..427e2d6f5a 100644 --- a/samtranslator/model/stepfunctions/generators.py +++ b/samtranslator/model/stepfunctions/generators.py @@ -40,6 +40,7 @@ def __init__( definition_substitutions, role, state_machine_type, + tracing, events, event_resources, event_resolver, @@ -62,6 +63,7 @@ def __init__( :param definition_substitutions: Variable-to-value mappings to be replaced in the State Machine definition :param role: Role ARN to use for the execution role :param state_machine_type: Type of the State Machine + :param tracing: Tracing configuration for the State Machine :param events: List of event sources for the State Machine :param event_resources: Event resources to link :param event_resolver: Resolver that maps Event types to Event classes @@ -83,6 +85,7 @@ def __init__( self.definition_substitutions = definition_substitutions self.role = role self.type = state_machine_type + self.tracing = tracing self.events = events self.event_resources = event_resources self.event_resolver = event_resolver @@ -144,6 +147,7 @@ def to_cloudformation(self): self.state_machine.StateMachineName = self.name self.state_machine.StateMachineType = self.type self.state_machine.LoggingConfiguration = self.logging + self.state_machine.TracingConfiguration = self.tracing self.state_machine.Tags = self._construct_tag_list() event_resources = self._generate_event_resources() diff --git a/samtranslator/model/stepfunctions/resources.py b/samtranslator/model/stepfunctions/resources.py index 1603421364..497e17975f 100644 --- a/samtranslator/model/stepfunctions/resources.py +++ b/samtranslator/model/stepfunctions/resources.py @@ -15,6 +15,7 @@ class StepFunctionsStateMachine(Resource): "StateMachineType": PropertyType(False, is_str()), "Tags": PropertyType(False, list_of(is_type(dict))), "DefinitionSubstitutions": PropertyType(False, is_type(dict)), + "TracingConfiguration": PropertyType(False, is_type(dict)), } runtime_attrs = { diff --git a/tests/model/stepfunctions/test_state_machine_generator.py b/tests/model/stepfunctions/test_state_machine_generator.py index d92e1179e9..762242fa7a 100644 --- a/tests/model/stepfunctions/test_state_machine_generator.py +++ b/tests/model/stepfunctions/test_state_machine_generator.py @@ -22,6 +22,7 @@ def setUp(self): "definition_substitutions": None, "role": None, "state_machine_type": None, + "tracing": None, "events": None, "event_resources": None, "event_resolver": None, diff --git a/tests/translator/input/state_machine_with_xray.yaml b/tests/translator/input/state_machine_with_xray.yaml new file mode 100644 index 0000000000..f5e56e7294 --- /dev/null +++ b/tests/translator/input/state_machine_with_xray.yaml @@ -0,0 +1,10 @@ +Resources: + StateMachine: + Type: AWS::Serverless::StateMachine + Properties: + Name: MyStateMachineWithXRayTracing + Type: STANDARD + DefinitionUri: s3://sam-demo-bucket/my-state-machine.asl.json + Role: arn:aws:iam::123456123456:role/service-role/SampleRole + Tracing: + Enabled: true diff --git a/tests/translator/output/aws-cn/state_machine_with_xray.json b/tests/translator/output/aws-cn/state_machine_with_xray.json new file mode 100644 index 0000000000..156d59d448 --- /dev/null +++ b/tests/translator/output/aws-cn/state_machine_with_xray.json @@ -0,0 +1,25 @@ +{ + "Resources": { + "StateMachine": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "Tags": [ + { + "Value": "SAM", + "Key": "stateMachine:createdBy" + } + ], + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachineWithXRayTracing", + "TracingConfiguration": { + "Enabled": true + }, + "StateMachineType": "STANDARD", + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/state_machine_with_xray.json b/tests/translator/output/aws-us-gov/state_machine_with_xray.json new file mode 100644 index 0000000000..156d59d448 --- /dev/null +++ b/tests/translator/output/aws-us-gov/state_machine_with_xray.json @@ -0,0 +1,25 @@ +{ + "Resources": { + "StateMachine": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "Tags": [ + { + "Value": "SAM", + "Key": "stateMachine:createdBy" + } + ], + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachineWithXRayTracing", + "TracingConfiguration": { + "Enabled": true + }, + "StateMachineType": "STANDARD", + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/state_machine_with_xray.json b/tests/translator/output/state_machine_with_xray.json new file mode 100644 index 0000000000..156d59d448 --- /dev/null +++ b/tests/translator/output/state_machine_with_xray.json @@ -0,0 +1,25 @@ +{ + "Resources": { + "StateMachine": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "Tags": [ + { + "Value": "SAM", + "Key": "stateMachine:createdBy" + } + ], + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachineWithXRayTracing", + "TracingConfiguration": { + "Enabled": true + }, + "StateMachineType": "STANDARD", + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index ce8400b6e1..72ecdac579 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -298,6 +298,7 @@ class TestTranslatorEndToEnd(TestCase): "state_machine_with_api_resource_policy", "state_machine_with_api_auth_default_scopes", "state_machine_with_condition_and_events", + "state_machine_with_xray", "function_with_file_system_config", ], [