aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.66k stars 3.92k forks source link

(aws-scheduler-targets-alpha): Add targets.CodePipelineStartPipelineExecution Target #27449

Closed filletofish closed 10 months ago

filletofish commented 1 year ago

Describe the feature

Work to support L2 constructs for AWS Scheduler is in progress (https://github.com/aws/aws-cdk/issues/23394). See the approved RFC. RFC planned to add 12 templates targets, but only Lambda Invoke is currently implemented (https://github.com/aws/aws-cdk/pull/26575).

This issue tracks implementation of CodePipelineStartPipelineExecution target to start an AWS CodePipeline execution.

Use Case

Customers would like to use templated target CodePipelineStartPipelineExecution to be able to start AWS CodePipeline execution with AWS Scheduler. L2 target construct should grant required permissions to the AWS Scheduler to start the CodePipeline execution.

Proposed Solution

The proposed solution needs to be adopted to the recent examples of LambdaInvoke (https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/aws-scheduler-targets-alpha/lib/lambda-invoke.ts).

Solution should also include unit and integration tests.

export class CodePipelineStartPipelineExecution  extends ScheduleTargetBase implements IScheduleTarget {
    constructor(
      private readonly pipeline: codepipeline.IPipeline,
      private readonly props: ScheduleTargetBaseProps,
    ) {
      super(props, pipeline.pipelineArn);
    }

   protected addTargetActionToRole(schedule: ISchedule, role: IRole): void {
      // TODO: Check if target and schedule are in the same account and region
      // TODO: Check if target and role are in the same account

      // TODO: Check if L2 grant methods can be used      
      role.addToPrincipalPolicy(new iam.PolicyStatement({
        actions: ['codepipeline:StartPipelineExecution'],
        resources: [this.pipeline.pipelineArn],
      }));
    }
  }

Other Information

No response

Acknowledgements

CDK version used

2.99.1

Environment details (OS name and version, etc.)

MacOs

github-actions[bot] commented 10 months ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.