diff --git a/index.ts b/index.ts index ef6ed44..c046f77 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,5 @@ import * as pathlib from 'path'; -import { Stack, Duration, Arn } from 'aws-cdk-lib'; +import { Duration, Arn } from 'aws-cdk-lib'; import * as ecs from 'aws-cdk-lib/aws-ecs'; import * as events from 'aws-cdk-lib/aws-events'; import * as eventsTargets from 'aws-cdk-lib/aws-events-targets'; @@ -13,7 +13,6 @@ export interface MutableTagEcsUpdaterProps { ecsService: ecs.IBaseService; pullSecret: secretsmanager.ISecret; autoUpdateRate?: string; - clusterStack?: Stack; } export class MutableTagEcsUpdater extends Construct { @@ -52,19 +51,22 @@ export class MutableTagEcsUpdater extends Construct { resources: ['*'], }), ); + + const clusterArnParts = Arn.parse(props.ecsCluster.clusterArn); + const clusterTasksArn = Arn.format( + { + ...clusterArnParts, + resource: 'task', + resourceName: `${clusterArnParts.resourceName}/*`, + }, + ); + tagUpdateLambda.addToRolePolicy( new iam.PolicyStatement({ actions: ['ecs:DescribeTasks'], resources: [ `${props.ecsService.serviceArn}/*`, - Arn.format( - { - resource: 'task', - service: 'ecs', - resourceName: `${props.ecsCluster.clusterName}/*`, - }, - props.clusterStack, - ), + clusterTasksArn, ], }), );