-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Multiple S3SourceActions returns "already a Construct with name" error #4237
Comments
This appears to be an issue with trying to use
|
Thanks for opening the issue @joekiller . You're correct; a quick way to unblock yourself is to change one the of those I'll see what I can do here - the edge case here is that you're using the same bucket twice in the pipeline, with different paths, which we didn't anticipate. |
I can reproduce this same error on a different context: I'm reusing lambdas when assigning I can provide a repro example if necessary. BTW: My current workaround is to just remove the shared lambda stack and declare each lambda within the cloudformation stacks. |
That would be helpful @skyrpex . |
I managed to move it into a single file. All the cdk commands throw error, but I found In this case, there's a SharedLambdas stack which contains a lambda used in the other two PWA stacks, but I guess it'll throw the same error reusing the same lambda in multiple distributions on the same stack. import * as cdk from "@aws-cdk/core";
import * as s3 from "@aws-cdk/aws-s3";
import * as lambda from "@aws-cdk/aws-lambda";
import * as cloudfront from "@aws-cdk/aws-cloudfront";
class SharedPwaLambdasStack extends cdk.Stack {
addCspHeadersFunction: lambda.Function;
constructor(scope: cdk.Construct, name: string, props?: cdk.StackProps) {
super(scope, name, props);
this.addCspHeadersFunction = new lambda.Function(this, "AddCspHeaders", {
runtime: lambda.Runtime.NODEJS_8_10,
handler: "index.handler",
code: lambda.Code.fromInline("irrelevant"),
});
}
}
interface PwaStackProps extends cdk.StackProps {
addCspHeadersFunction: lambda.Function;
}
class PwaStack extends cdk.Stack {
constructor(scope: cdk.Construct, name: string, props: PwaStackProps) {
super(scope, name, props);
const bucket = new s3.Bucket(this, `${name}Bucket`);
const distribution = new cloudfront.CloudFrontWebDistribution(this, `${name}Distribution`, {
originConfigs: [
{
s3OriginSource: {
s3BucketSource: bucket,
},
behaviors: [
{
isDefaultBehavior: true,
lambdaFunctionAssociations: [
{
eventType: cloudfront.LambdaEdgeEventType.VIEWER_RESPONSE,
lambdaFunction: props.addCspHeadersFunction.latestVersion,
},
],
},
],
},
],
});
}
}
const app = new cdk.App();
const sharedPwaLambdasStack = new SharedPwaLambdasStack(app, "SharedPwaLambdas");
const websitePwa = new PwaStack(app, "WebsitePwa", {
addCspHeadersFunction: sharedPwaLambdasStack.addCspHeadersFunction,
});
// If you comment the following stack, it will work.
const adminPwa = new PwaStack(app, "AdminPwa", {
addCspHeadersFunction: sharedPwaLambdasStack.addCspHeadersFunction,
}); |
And what is the error that you get? Because you don't share buckets in this case (each instance of |
Oh sure, here it is: Here's the full error stack.
|
Got it. I think that's a completely different error - the message is the same, but the root cause (where is the duplication happening) is totally different in your case @skyrpex . |
Then I'm so glad I gave you the reproduction code. Shall we create a new issue, then? |
Sorry about that. I've opened a new issue, and copied your information there: #4459 |
…ket multiple times If you attempted to add two source S3 actions using the same bucket into the same pipeline, and both using CloudWatch events as triggers, you would get an error about 'duplicate construct with id PipelineSourceEventRule'. This is a valid use-case, though, as each action might point to a different path in the bucket. Fixes aws#4237
…ket multiple times If you attempted to add two source S3 actions using the same bucket into the same pipeline, and both using CloudWatch events as triggers, you would get an error about 'duplicate construct with id PipelineSourceEventRule'. This is a valid use-case, though, as each action might point to a different path in the bucket. Fixes aws#4237
…ket multiple times (#4481) If you attempted to add two source S3 actions using the same bucket into the same pipeline, and both using CloudWatch events as triggers, you would get an error about 'duplicate construct with id PipelineSourceEventRule'. This is a valid use-case, though, as each action might point to a different path in the bucket. Fixes #4237
Thanks @skinny85 I'll get an example for my other issue. |
NP @joekiller , glad it's working now! |
When adding more than one S3SourceAction to a pipeline I get a duplicate Construct name error.
Reproduction Steps
Error Log
Environment
Other
N/A
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: