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

[aws-codepipeline-actions] Not able to use EVENTS based S3 trigger when bucketKey contains a CDK token #9554

Closed
jimistry123 opened this issue Aug 9, 2020 · 2 comments · Fixed by #9575
Assignees
Labels
@aws-cdk/aws-codepipeline-actions effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1

Comments

@jimistry123
Copy link

❓ General Issue

The Question

I am trying to use S3SourceAction class to define a bunch of S3 sources for a Pipeline. The bucket key for the source action is determined during deployment time using a CFN custom resource. This is how I am building an object for S3SourceAction:

public S3SourceAction createS3SourceAction(String projectName, Artifact outputArtifact) {
        // The getFileName() method will create a custom resource which will determine the filename.
        String bucketKey = "rpms/" + projectName + "/" + getFileName(projectName, artifactsBucketName);
        return S3SourceAction.Builder.create()
                .actionName(projectName)
                .bucket(artifactsBucket)
                .bucketKey(bucketKey)
                .output(outputArtifact)
                .trigger(S3Trigger.EVENTS)
                .build();
    }

Now, because the S3 trigger is set to EVENTS, CDK will automatically create a corresponding CloudWatch Events rule as a dependency. I noticed that the logical ID of the CW rule will include the bucket key in it. And because of the way I am setting bucket key, the bucket key contains a CDK token during stack synthesis.

So when I try to synthesize my stack, it throws the following error:

Exception in thread "main" software.amazon.jsii.JsiiException: Cannot use tokens in construct ID: <dynamically-generated-logical-ID>/rpms/${Token[Default.Response.4408]}

I came across #1374 which explains why CDK does not allow to use tokens in construct ID.

So my question is - Since I have no control over the logical ID of the dependent CloudWatch Events rule, is it possible to set an event based trigger on a dynamically generated bucket key? If there is a workaround or a better way to this then that would be great.

Environment

  • CDK CLI Version: 1.42.0 (build 3b64241)
  • Module Version: Same as CDK version (1.42.0)
  • Node.js Version: v12.16.3
  • OS: macOS Mojave
  • Language (Version): Java 8

Other information

@jimistry123 jimistry123 added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Aug 9, 2020
@skinny85
Copy link
Contributor

Hey @jimistry123 ,

you're right, this is probably a miss in the construct library for codepipeline.

To unblock yourself, you can set the trigger property to S3Trigger.NONE, and create the Event yourself:

var action = S3SourceAction.Builder.create()
                .actionName(projectName)
                .bucket(artifactsBucket)
                .bucketKey(bucketKey)
                .output(outputArtifact)
                .trigger(S3Trigger.NONE)
                .build();

        artifactsBucket.onCloudTrailPutObject("some-id", OnCloudTrailBucketEventOptions.builder()
                .target(new CodePipeline(pipeline))
                .paths(Collections.singletonList(bucketKey))
                .build()
        );

@skinny85
Copy link
Contributor

I'll work on a fix for this in the meantime.

@skinny85 skinny85 added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Aug 10, 2020
@SomayaB SomayaB removed the guidance Question that needs advice or information. label Aug 10, 2020
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Aug 10, 2020
…ketKey a Token

We use bucketKey to differentiate between multiple source actions
that observe the same bucket using trigger=Events.
However, we can't do that if bucketKey is a lazy value,
as Tokens can't be used as parts of identifier for the created Event.
So, check for that case explicitly.

Fixes aws#9554
@SomayaB SomayaB added the in-progress This issue is being actively worked on. label Aug 11, 2020
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Aug 12, 2020
…ketKey a Token

We use bucketKey to differentiate between multiple source actions
that observe the same bucket using trigger=Events.
However, we can't do that if bucketKey is a lazy value,
as Tokens can't be used as parts of identifier for the created Event.
So, check for that case explicitly.

Fixes aws#9554
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Aug 12, 2020
…ketKey a Token

We use bucketKey to differentiate between multiple source actions
that observe the same bucket using trigger=Events.
However, we can't do that if bucketKey is a lazy value,
as Tokens can't be used as parts of identifier for the created Event.
So, check for that case explicitly.

Fixes aws#9554
@mergify mergify bot closed this as completed in #9575 Aug 13, 2020
mergify bot pushed a commit that referenced this issue Aug 13, 2020
…ketKey a Token (#9575)

We use bucketKey to differentiate between multiple source actions
that observe the same bucket using trigger=Events.
However, we can't do that if bucketKey is a lazy value,
as Tokens can't be used as parts of identifier for the created Event.
So, check for that case explicitly.

Fixes #9554

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codepipeline-actions effort/small Small work item – less than a day of effort in-progress This issue is being actively worked on. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants