Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(codepipeline-actions): add pipeline invoke action support. #34039

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hwum
Copy link
Contributor

@hwum hwum commented Apr 3, 2025

Issue # 33818

Closes #33818
#33818

Reason for this change

Codepipeline team launched pipeline invoke action last year, but not available in cdk library yet.

Description of changes

Pipeline invoke action support

Describe any new or updated permissions being added

no

Description of how you validated changes

Unit test, local deployment, integ test.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Apr 3, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team April 3, 2025 23:56
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@hwum hwum changed the title feat(codepipeline-actions):support pipeline invoke action feat(codepipeline-actions): add pipeline invoke action support. Apr 4, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review April 4, 2025 00:04

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Copy link

codecov bot commented Apr 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (74cbe27) to head (4802233).
Report is 28 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #34039   +/-   ##
=======================================
  Coverage   83.98%   83.98%           
=======================================
  Files         120      120           
  Lines        6976     6976           
  Branches     1178     1178           
=======================================
  Hits         5859     5859           
  Misses       1005     1005           
  Partials      112      112           
Flag Coverage Δ
suite.unit 83.98% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 83.98% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hwum hwum force-pushed the l2 branch 5 times, most recently from 5981f91 to 66dd46d Compare April 4, 2025 06:06
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 4, 2025
@@ -0,0 +1,88 @@
import { Stack } from 'aws-cdk-lib';
import { RevisionType } from 'aws-cdk-lib/aws-codepipeline-actions';
import { app } from '../../aws-appmesh/test/integ.mesh-port-match';
Copy link
Contributor

@go-to-k go-to-k Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

../../aws-appmesh/test/integ.mesh-port-match

Is this a mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revised.

Comment on lines 16 to 24
const repo = new codecommit.Repository(stack, 'MyRepo', {
repositoryName: 'my-repo',
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeCommit has already stopped accepting new ones, so it would be better to use other source actions in case another developer takes over this test in the future, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update in the next revision. Thanks for mentioning


const integrationTest = new IntegTest(app, 'codepipeline-integ-test', {
testCases: [stack],
stackUpdateWorkflow: false,
Copy link
Contributor

@go-to-k go-to-k Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stackUpdateWorkflow: false,

Is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assertion is recommended actually. Not necessary.

Comment on lines +86 to +102
const awsApiCall1 = integrationTest.assertions.awsApiCall('CodePipeline', 'getPipeline', { name: pipelineName });
awsApiCall1.assertAtPath('pipeline.name', ExpectedResult.stringLikeRegexp(pipelineName));
awsApiCall1.assertAtPath('pipeline.stages.1.actions.1.name', ExpectedResult.stringLikeRegexp('Invoke'));
Copy link
Contributor

@go-to-k go-to-k Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using the assertions that actually run the pipeline (for startPipelineExecution and getPipelineState with Succeeded status), which I thought could be used to check IAM permissions etc.

ref: https://github.com/aws/aws-cdk/blob/v2.188.0/packages/@aws-cdk-testing/framework-integ/test/aws-codepipeline-actions/test/integ.pipeline-ecr-build-and-publish-public.ts#L84-L112

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the cdk integ test should be testing cdk input -> cfn input -> service The goal of these tests are checking if backend service correctly received the parameters from cdk app. The IAM and PipelineExecution are more about functionalities, which have been well checked in our internal tests, so I don't think they're necessary..

Copy link
Contributor

@go-to-k go-to-k Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your perspective, but I see it a bit differently. This is L2 construct, not L1 construct. L2 constructs are not just simple wrappers around CloudFormation - they provide sensible defaults and recommended configurations. That's why the bound method automatically configures and sets appropriate IAM permissions by default.
However, there's always a possibility that CDK contributors might implement inappropriate IAM settings. Where would we catch such issues? Unit tests only verify input/output matching and can't cover this aspect. In my view, integ tests are precisely the place to verify the actual behavior of CDK's internal code.

Copy link
Contributor

@go-to-k go-to-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, as I haven't used this new action yet, but can this action be used cross-accounting?
If so, should we support it in this action class? Or is this action intended to be performed within a single account?

Comment on lines 11 to 15
/**
* The name of the pipeline that will, upon running, start the current target pipeline.
* You must have already created the invoking pipeline.
*/
readonly pipelineName: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using IPipeline?

Copy link
Contributor

@go-to-k go-to-k Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was mistaken. I thought this was the name of the target pipeline, but it is the name of the pipeline that executes this action.
So it was my understanding that it is impossible to pass the pipeline to which this action belongs...

PS.) No, was my perception correct...?

Please let me know if my understanding is different. (It's a bit confusing, so even if we don't use IPipeline, we might as well change the property name in the CDK.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would insist on the pipelineName since the targetPipeline could not be created by cdk... If customers have a pipeline created by console or terraform, they cannot use IPipeline here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revise here to reduce the ambiguity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-PipelineInvoke.html this doc is kind of confusing, I already asked the doc team to improve

Copy link
Contributor

@go-to-k go-to-k Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would insist on the pipelineName since the targetPipeline could not be created by cdk... If customers have a pipeline created by console or terraform, they cannot use IPipeline here

The interfaces starting with 'I' like IPipeline are specifically designed to import resources (called unowned resources) created outside of CDK (such as through the console or Terraform) into your stack.

https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md#owned-vs-unowned-constructs

You can use methods like fromPipelineArn to virtually incorporate these external resources into your stack. This approach allows you to use convenient features like onEvent methods on imported resources, unlike with primitive types.

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-codepipeline/lib/pipeline.ts#L538-L542

const unownedPipelineArn = 'MyUnownedPipelineArn';

// importedPipeline: IPipeline
const importedPipeline = Pipeline.fromPipelineArn(this, 'ImportedPipeline', unownedPipelineArn);

// can use like construct
imported.onEvent('test');
console.log(imported.pipelineArn);
console.log(imported.pipelineName);

new OtherResource(this, 'OtherResource', {
  pipeline: importedPipeline,
});

Additionally, using primitive type properties (i.e. physical attributes) in props is generally not recommended in CDK design.

https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md#types

Comment on lines +114 to +116
actions: ['codepipeline:StartPipelineExecution'],
resources: ['*'],
Copy link
Contributor

@go-to-k go-to-k Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to the comment above, could IPipeline in this props be used to properly narrow down the resources instead of *? (using pipeline.pipelineArn)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be relevant to the following comment...

I'm not sure, as I haven't used this new action yet, but can this action be used cross-accounting?
If so, should we support it in this action class? Or is this action intended to be performed within a single account?

Copy link
Contributor

@go-to-k go-to-k Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related: #34039 (comment)

Comment on lines 28 to 30
}
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
/**
}
/**

Comment on lines 41 to 44
readonly revisionType: RevisionType;
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
readonly revisionType: RevisionType;
/**
readonly revisionType: RevisionType;
/**

Comment on lines 79 to 82
S3_OBJECT_VERSION_ID = 'S3_OBJECT_VERSION_ID',

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
S3_OBJECT_VERSION_ID = 'S3_OBJECT_VERSION_ID',
/**
S3_OBJECT_VERSION_ID = 'S3_OBJECT_VERSION_ID',
/**

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 4, 2025
Comment on lines +49 to +63
/**
* A pipeline-level variable used for a pipeline execution.
*/
export interface Variable {
/**
* The name of a pipeline-level variable.
*/
readonly name: string;

/**
* The value of a pipeline-level variable.
*/
readonly value: string;
Copy link
Contributor

@go-to-k go-to-k Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the variables generated here are to be used in the target pipeline, do they need to be called in the following form?: #{variables.xxx}

If so, wouldn't it be more convenient to create a class with a method to wrap this behaviour and use an instance of that class?

ref: https://github.com/aws/aws-cdk/blob/v2.188.0/packages/aws-cdk-lib/aws-codepipeline/lib/variable.ts#L69-L71

The class in that file is for VariableDeclaration so we can't use it here, and we need a new class.

P.S.) "Variable namespace" is available in the management console, but cannot it be specified in CloudFormation?

variables

@@ -0,0 +1,88 @@
import { Stack } from 'aws-cdk-lib';
import { RevisionType } from 'aws-cdk-lib/aws-codepipeline-actions';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the definition below this one. (line 4)

import * as cpactions from 'aws-cdk-lib/aws-codepipeline-actions';

Copy link
Contributor

@go-to-k go-to-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

*/
COMMIT_ID = 'COMMIT_ID',
/**
* The revision type is a image digest.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The revision type is a image digest.
* The revision type is an image digest.

*/
IMAGE_DIGEST = 'IMAGE_DIGEST',
/**
* The revision type is a s3 object version id.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The revision type is a s3 object version id.
* The revision type is an S3 object version id.

S3_OBJECT_VERSION_ID = 'S3_OBJECT_VERSION_ID',

/**
* The revision type is a s3 object version key.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The revision type is a s3 object version key.
* The revision type is an S3 object version key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bring this up lol. I'll talk to our AI team for this issue

Comment on lines +6 to +7
import * as cpactions from '../../lib';
import { RevisionType } from '../../lib';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be merged.


/* eslint-disable quote-props */

describe('', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be removed.

}));
});

function stackIncludingPipelineInvokeCodePipeline(pipelineName: string, app?: App) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to get it out of the 'describe' so that it can be used in other tests.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 4802233
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

codepipeline-actions: support CodePipeline invoke action
4 participants