From e8f20c41fd9b579903b242e291bae65fb62efdd7 Mon Sep 17 00:00:00 2001 From: gracelu0 Date: Mon, 28 Oct 2024 16:37:13 -0700 Subject: [PATCH] fix unit test role ids --- .../aws-scheduler-targets-alpha/lib/target.ts | 5 +++++ .../test/codebuild-start-build.test.ts | 11 ++++++----- ...depipeline-start-pipeline-execution.test.ts | 11 ++++++----- .../test/event-bridge-put-events.test.ts | 11 ++++++----- .../inspector-start-assessment-run.test.ts | 15 ++++++++------- .../kinesis-data-firehose-put-record.test.ts | 15 ++++++++------- .../test/kinesis-stream-put-record.test.ts | 11 ++++++----- .../test/lambda-invoke.test.ts | 18 +++++++++--------- ...sage-maker-start-pipeline-execution.test.ts | 2 +- .../test/sns-publish.test.ts | 9 +++++---- .../test/sqs-send-message.test.ts | 15 ++++++++------- .../test/stepfunction-start-execution.test.ts | 11 ++++++----- 12 files changed, 74 insertions(+), 60 deletions(-) diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/lib/target.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/lib/target.ts index 8677d3d6fd07e..a625582c53a4e 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/lib/target.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/lib/target.ts @@ -126,6 +126,11 @@ export abstract class ScheduleTargetBase { }, }); if (existingRole) { + existingRole.assumeRolePolicy?.addStatements(new iam.PolicyStatement({ + effect: iam.Effect.ALLOW, + principals: [principal], + actions: ['sts:AssumeRole'], + })); return existingRole; } const role = new iam.Role(stack, id, { diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codebuild-start-build.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codebuild-start-build.test.ts index 4989308395e4e..b8732648ebfeb 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codebuild-start-build.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codebuild-start-build.test.ts @@ -14,6 +14,7 @@ describe('codebuild start build', () => { const codebuildArnRef = { 'Fn::GetAtt': ['ProjectC78D97AD', 'Arn'] }; const codebuildAction = 'codebuild:StartBuild'; const expr = ScheduleExpression.at(new Date(Date.UTC(1991, 2, 24, 0, 0, 0))); + const roleId = 'SchedulerRoleForTarget27bd47517CF0F8'; beforeEach(() => { app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } }); @@ -36,7 +37,7 @@ describe('codebuild start build', () => { Properties: { Target: { Arn: codebuildArnRef, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: {}, }, }, @@ -52,7 +53,7 @@ describe('codebuild start build', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }); template.hasResourceProperties('AWS::IAM::Role', { @@ -113,7 +114,7 @@ describe('codebuild start build', () => { }); }); - test('reuses IAM role and IAM policy for two schedules from the same account', () => { + test('reuses IAM role and IAM policy for two schedules with the same target from the same account', () => { const codeBuildTarget = new CodeBuildStartBuild(codebuildProject, {}); new Schedule(stack, 'MyScheduleDummy1', { @@ -154,7 +155,7 @@ describe('codebuild start build', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }, 1); }); @@ -411,7 +412,7 @@ describe('codebuild start build', () => { Properties: { Target: { Arn: codebuildArnRef, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: { MaximumEventAgeInSeconds: 10800, MaximumRetryAttempts: 5, diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codepipeline-start-pipeline-execution.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codepipeline-start-pipeline-execution.test.ts index ba20a797536bd..d2218d47f8316 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codepipeline-start-pipeline-execution.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/codepipeline-start-pipeline-execution.test.ts @@ -28,6 +28,7 @@ describe('codepipeline start execution', () => { ], }; const expr = ScheduleExpression.at(new Date(Date.UTC(1991, 2, 24, 0, 0, 0))); + const roleId = 'SchedulerRoleForTarget1b3000F5862F75'; beforeEach(() => { app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } }); @@ -48,7 +49,7 @@ describe('codepipeline start execution', () => { Properties: { Target: { Arn: pipelineArn, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: {}, }, }, @@ -64,7 +65,7 @@ describe('codepipeline start execution', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }); template.hasResourceProperties('AWS::IAM::Role', { @@ -123,7 +124,7 @@ describe('codepipeline start execution', () => { }); }); - test('reuses IAM role and IAM policy for two schedules from the same account', () => { + test('reuses IAM role and IAM policy for two schedules with the same target from the same account', () => { const codepipelineTarget = new CodePipelineStartPipelineExecution(codepipeline, {}); new Schedule(stack, 'MyScheduleDummy1', { @@ -164,7 +165,7 @@ describe('codepipeline start execution', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }, 1); }); @@ -431,7 +432,7 @@ describe('codepipeline start execution', () => { Properties: { Target: { Arn: pipelineArn, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: { MaximumEventAgeInSeconds: 10800, MaximumRetryAttempts: 5, diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/event-bridge-put-events.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/event-bridge-put-events.test.ts index 2c99799377177..791c477914424 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/event-bridge-put-events.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/event-bridge-put-events.test.ts @@ -12,6 +12,7 @@ describe('eventBridge put events', () => { let eventBus: events.EventBus; let eventBusEventEntry: EventBridgePutEventsEntry; const expr = ScheduleExpression.at(new Date(Date.UTC(1991, 2, 24, 0, 0, 0))); + const roleId = 'SchedulerRoleForTarget1e6d0e3BE2318C'; beforeEach(() => { app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } }); @@ -48,7 +49,7 @@ describe('eventBridge put events', () => { Source: 'service', }, Input: JSON.stringify({ foo: 'bar' }), - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: {}, }, }, @@ -69,7 +70,7 @@ describe('eventBridge put events', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }); template.hasResourceProperties('AWS::IAM::Role', { @@ -144,7 +145,7 @@ describe('eventBridge put events', () => { }); }); - test('reuses IAM role and IAM policy for two schedules from the same account', () => { + test('reuses IAM role and IAM policy for two schedules with the same target from the same account', () => { const eventBusTarget = new EventBridgePutEvents(eventBusEventEntry, {}); new Schedule(stack, 'MyScheduleDummy1', { @@ -190,7 +191,7 @@ describe('eventBridge put events', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }, 1); }); @@ -513,7 +514,7 @@ describe('eventBridge put events', () => { Source: 'service', }, Input: JSON.stringify({ foo: 'bar' }), - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: { MaximumEventAgeInSeconds: 10800, MaximumRetryAttempts: 5, diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/inspector-start-assessment-run.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/inspector-start-assessment-run.test.ts index b9bb4a9bc1f1c..74935cd2ddc5e 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/inspector-start-assessment-run.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/inspector-start-assessment-run.test.ts @@ -11,6 +11,7 @@ describe('schedule target', () => { let stack: Stack; let template: CfnAssessmentTemplate; const expr = ScheduleExpression.at(new Date(Date.UTC(1969, 10, 20, 0, 0, 0))); + const roleId = 'SchedulerRoleForTarget78b2d848BF7444'; beforeEach(() => { app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } }); @@ -37,7 +38,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['MyTemplate', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: {}, }, }, @@ -53,7 +54,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -113,7 +114,7 @@ describe('schedule target', () => { }); }); - test('reuses IAM role and IAM policy for two schedules from the same account', () => { + test('reuses IAM role and IAM policy for two schedules with the same target from the same account', () => { const inspectorTarget = new InspectorStartAssessmentRun(template); new Schedule(stack, 'MyScheduleDummy1', { @@ -152,7 +153,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }, 1); }); @@ -183,7 +184,7 @@ describe('schedule target', () => { Arn: { 'Fn::ImportValue': 'Stack2:ExportsOutputFnGetAttAnotherTemplateArn9F673A62', }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTargetea46910831E154', 'Arn'] }, RetryPolicy: {}, }, }, @@ -199,7 +200,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: 'SchedulerRoleForTargetea46910831E154' }], }); }); @@ -461,7 +462,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['MyTemplate', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: { MaximumEventAgeInSeconds: 10800, MaximumRetryAttempts: 5, diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-data-firehose-put-record.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-data-firehose-put-record.test.ts index ee3e2b5b55f47..7d8a5c8f685b1 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-data-firehose-put-record.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-data-firehose-put-record.test.ts @@ -11,6 +11,7 @@ describe('schedule target', () => { let stack: Stack; let firehose: CfnDeliveryStream; const expr = ScheduleExpression.at(new Date(Date.UTC(1969, 10, 20, 0, 0, 0))); + const roleId = 'SchedulerRoleForTarget380bba149146B2'; beforeEach(() => { app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } }); @@ -32,7 +33,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['MyFirehose', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: {}, }, }, @@ -50,7 +51,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -112,7 +113,7 @@ describe('schedule target', () => { }); }); - test('reuses IAM role and IAM policy for two schedules from the same account', () => { + test('reuses IAM role and IAM policy for two schedules with the same target from the same account', () => { const firehoseTarget = new KinesisDataFirehosePutRecord(firehose); new Schedule(stack, 'MyScheduleDummy1', { @@ -153,7 +154,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }, 1); }); @@ -179,7 +180,7 @@ describe('schedule target', () => { Arn: { 'Fn::ImportValue': 'Stack2:ExportsOutputFnGetAttAnotherFirehoseArn24CBF54A', }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget4b70ebDC2428DE', 'Arn'] }, RetryPolicy: {}, }, }, @@ -197,7 +198,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: 'SchedulerRoleForTarget4b70ebDC2428DE' }], }); }); @@ -447,7 +448,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['MyFirehose', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: { MaximumEventAgeInSeconds: 10800, MaximumRetryAttempts: 5, diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-stream-put-record.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-stream-put-record.test.ts index 523b1da25571e..feadcb29f6582 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-stream-put-record.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/kinesis-stream-put-record.test.ts @@ -11,6 +11,7 @@ describe('schedule target', () => { let stack: Stack; let stream: kinesis.Stream; const expr = ScheduleExpression.at(new Date(Date.UTC(1969, 10, 20, 0, 0, 0))); + const roleId = 'SchedulerRoleForTargetb38bb9039D30C1'; beforeEach(() => { app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } }); @@ -34,7 +35,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['MyStream5C050E93', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: {}, KinesisParameters: { PartitionKey: 'key', @@ -55,7 +56,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -121,7 +122,7 @@ describe('schedule target', () => { }); }); - test('reuses IAM role and IAM policy for two schedules from the same account', () => { + test('reuses IAM role and IAM policy for two schedules with the same target from the same account', () => { const streamTarget = new KinesisStreamPutRecord(stream, { partitionKey: 'key', }); @@ -164,7 +165,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }, 1); }); @@ -437,7 +438,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['MyStream5C050E93', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: { MaximumEventAgeInSeconds: 10800, MaximumRetryAttempts: 5, diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/lambda-invoke.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/lambda-invoke.test.ts index 0bebd8590d8fe..6a141b1e54670 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/lambda-invoke.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/lambda-invoke.test.ts @@ -39,7 +39,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget9afb73C641D024', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget637b5173FB8068', 'Arn'] }, RetryPolicy: {}, }, }, @@ -65,7 +65,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: 'SchedulerRoleForTarget637b5173FB8068' }], }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -104,7 +104,7 @@ describe('schedule target', () => { Arn: { Ref: 'MyLambdaVersion2EF97E33', }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTargetd8a041965BDCA6', 'Arn'] }, RetryPolicy: {}, }, }, @@ -122,7 +122,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: 'SchedulerRoleForTargetd8a041965BDCA6' }], }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -193,7 +193,7 @@ describe('schedule target', () => { }); }); - test('reuses IAM role and IAM policy for two schedules from the same account', () => { + test('reuses IAM role and IAM policy for two schedules with the same target from the same account', () => { const lambdaTarget = new LambdaInvoke(func, {}); new Schedule(stack, 'MyScheduleDummy1', { @@ -243,7 +243,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: 'SchedulerRoleForTarget637b5173FB8068' }], }, 1); }); @@ -310,7 +310,7 @@ describe('schedule target', () => { Arn: { Ref: 'MyLambdaAliasD26C43B4', }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget447112D2459CC7', 'Arn'] }, RetryPolicy: {}, }, }, @@ -328,7 +328,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: 'SchedulerRoleForTarget447112D2459CC7' }], }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -582,7 +582,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget637b5173FB8068', 'Arn'] }, RetryPolicy: { MaximumEventAgeInSeconds: 10800, MaximumRetryAttempts: 5, diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sage-maker-start-pipeline-execution.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sage-maker-start-pipeline-execution.test.ts index 70249d8289c3f..1472687dc6421 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sage-maker-start-pipeline-execution.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sage-maker-start-pipeline-execution.test.ts @@ -123,7 +123,7 @@ describe('schedule target', () => { }); }); - test('reuses IAM role and IAM policy for two schedules from the same account', () => { + test('reuses IAM role and IAM policy for two schedules with the same target from the same account', () => { const pipelineTarget = new SageMakerStartPipelineExecution(pipeline, { pipelineParameterList, }); diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sns-publish.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sns-publish.test.ts index 30c97216d1cd4..84787d4953864 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sns-publish.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sns-publish.test.ts @@ -11,6 +11,7 @@ describe('sns topic schedule target', () => { let stack: Stack; let topic: sns.ITopic; const scheduleExpression = scheduler.ScheduleExpression.at(new Date(Date.UTC(1969, 10, 20, 0, 0, 0))); + const roleId = 'SchedulerRoleForTarget0f6b2b82B558C1'; beforeEach(() => { app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } }); @@ -36,7 +37,7 @@ describe('sns topic schedule target', () => { }, RoleArn: { 'Fn::GetAtt': [ - 'SchedulerRoleForTarget1441a743A31888', 'Arn', + roleId, 'Arn', ], }, RetryPolicy: {}, @@ -57,7 +58,7 @@ describe('sns topic schedule target', () => { ], }, Roles: [{ - Ref: 'SchedulerRoleForTarget1441a743A31888', + Ref: roleId, }], }); @@ -185,7 +186,7 @@ describe('sns topic schedule target', () => { ], }, Roles: [{ - Ref: 'SchedulerRoleForTarget1441a743A31888', + Ref: roleId, }], }); }); @@ -459,7 +460,7 @@ describe('sns topic schedule target', () => { Ref: 'TopicBFC7AF6E', }, RoleArn: { - 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'], + 'Fn::GetAtt': [roleId, 'Arn'], }, RetryPolicy: { MaximumEventAgeInSeconds: 3600 * 3, diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sqs-send-message.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sqs-send-message.test.ts index 7462b6a53fa9b..6774b4641665d 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sqs-send-message.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/sqs-send-message.test.ts @@ -10,6 +10,7 @@ describe('schedule target', () => { let stack: Stack; let queue: sqs.IQueue; const expr = ScheduleExpression.at(new Date(Date.UTC(1969, 10, 20, 0, 0, 0))); + const roleId = 'SchedulerRoleForTarget9afb73C641D024'; beforeEach(() => { app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } }); @@ -31,7 +32,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['MyQueueE6CA6235', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: {}, }, }, @@ -49,7 +50,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -111,8 +112,8 @@ describe('schedule target', () => { }); }); - test('reuses IAM role and IAM policy for two schedules from the same account', () => { - const queueTarget = new SqsSendMessage(queue, { }); + test('reuses IAM role and IAM policy for two schedules with the same target from the same account', () => { + const queueTarget = new SqsSendMessage(queue, {}); new Schedule(stack, 'MyScheduleDummy1', { schedule: expr, @@ -152,7 +153,7 @@ describe('schedule target', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }, 1); }); @@ -413,7 +414,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['MyQueueE6CA6235', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: { MaximumEventAgeInSeconds: 10800, MaximumRetryAttempts: 5, @@ -479,7 +480,7 @@ describe('schedule target', () => { Arn: { 'Fn::GetAtt': ['FifoQueueE5FF7273', 'Arn'], }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget16f04eDD008E9F', 'Arn'] }, RetryPolicy: {}, SqsParameters: { MessageGroupId: 'messageGroupId', diff --git a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/stepfunction-start-execution.test.ts b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/stepfunction-start-execution.test.ts index 70c3b201f1e4c..cb18e3db1bd06 100644 --- a/packages/@aws-cdk/aws-scheduler-targets-alpha/test/stepfunction-start-execution.test.ts +++ b/packages/@aws-cdk/aws-scheduler-targets-alpha/test/stepfunction-start-execution.test.ts @@ -11,6 +11,7 @@ describe('stepfunction start execution', () => { let stack: Stack; let stepFunction: sfn.StateMachine; const expr = ScheduleExpression.at(new Date(Date.UTC(1991, 2, 24, 0, 0, 0))); + const roleId = 'SchedulerRoleForTargetc174eeEF9C09F9'; beforeEach(() => { app = new App({ context: { '@aws-cdk/aws-iam:minimizePolicies': true } }); @@ -35,7 +36,7 @@ describe('stepfunction start execution', () => { Arn: { Ref: 'MyStateMachine6C968CA5', }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: {}, }, }, @@ -51,7 +52,7 @@ describe('stepfunction start execution', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }); template.hasResourceProperties('AWS::IAM::Role', { @@ -112,7 +113,7 @@ describe('stepfunction start execution', () => { }); }); - test('reuses IAM role and IAM policy for two schedules from the same account', () => { + test('reuses IAM role and IAM policy for two schedules with the same target from the same account', () => { const stepFunctionTarget = new StepFunctionsStartExecution(stepFunction, {}); new Schedule(stack, 'MyScheduleDummy1', { @@ -153,7 +154,7 @@ describe('stepfunction start execution', () => { }, ], }, - Roles: [{ Ref: 'SchedulerRoleForTarget1441a743A31888' }], + Roles: [{ Ref: roleId }], }, 1); }); @@ -424,7 +425,7 @@ describe('stepfunction start execution', () => { Arn: { Ref: 'MyStateMachine6C968CA5', }, - RoleArn: { 'Fn::GetAtt': ['SchedulerRoleForTarget1441a743A31888', 'Arn'] }, + RoleArn: { 'Fn::GetAtt': [roleId, 'Arn'] }, RetryPolicy: { MaximumEventAgeInSeconds: 10800, MaximumRetryAttempts: 5,