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

fix(stepfunctions): allow disable x-ray #30808

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 20 additions & 14 deletions packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ export class StateMachine extends StateMachineBase {
stateMachineType: props.stateMachineType ?? undefined,
roleArn: this.role.roleArn,
loggingConfiguration: props.logs ? this.buildLoggingConfiguration(props.logs) : undefined,
tracingConfiguration: props.tracingEnabled ? this.buildTracingConfiguration() : undefined,
tracingConfiguration: this.buildTracingConfiguration(props.tracingEnabled),
...definitionBody.bind(this, this.role, props, graph),
definitionSubstitutions: props.definitionSubstitutions,
});
Expand Down Expand Up @@ -532,21 +532,27 @@ export class StateMachine extends StateMachineBase {
};
}

private buildTracingConfiguration(): CfnStateMachine.TracingConfigurationProperty {
this.addToRolePolicy(new iam.PolicyStatement({
// https://docs.aws.amazon.com/xray/latest/devguide/security_iam_id-based-policy-examples.html#xray-permissions-resources
// https://docs.aws.amazon.com/step-functions/latest/dg/xray-iam.html
actions: [
'xray:PutTraceSegments',
'xray:PutTelemetryRecords',
'xray:GetSamplingRules',
'xray:GetSamplingTargets',
],
resources: ['*'],
}));
private buildTracingConfiguration(isTracing?: boolean): CfnStateMachine.TracingConfigurationProperty | undefined {
if (isTracing === undefined) {
return undefined;
}

if (isTracing) {
this.addToRolePolicy(new iam.PolicyStatement({
// https://docs.aws.amazon.com/xray/latest/devguide/security_iam_id-based-policy-examples.html#xray-permissions-resources
// https://docs.aws.amazon.com/step-functions/latest/dg/xray-iam.html
actions: [
'xray:PutTraceSegments',
'xray:PutTelemetryRecords',
'xray:GetSamplingRules',
'xray:GetSamplingTargets',
],
resources: ['*'],
}));
}

return {
enabled: true,
enabled: isTracing,
};
}
}
Expand Down
19 changes: 19 additions & 0 deletions packages/aws-cdk-lib/aws-stepfunctions/test/state-machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,25 @@ describe('State Machine', () => {
});
});

test('disable tracing configuration', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new sfn.StateMachine(stack, 'MyStateMachine', {
definitionBody: sfn.DefinitionBody.fromChainable(sfn.Chain.start(new sfn.Pass(stack, 'Pass'))),
tracingEnabled: false,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::StepFunctions::StateMachine', {
DefinitionString: '{"StartAt":"Pass","States":{"Pass":{"Type":"Pass","End":true}}}',
TracingConfiguration: {
Enabled: false,
},
});
});

test('grant access', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down
Loading