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

S3 notifications lambda destination does not work with Function.fromFunctionArn #5592

Closed
wcauchois opened this issue Dec 30, 2019 · 3 comments · Fixed by #5599
Closed

S3 notifications lambda destination does not work with Function.fromFunctionArn #5592

wcauchois opened this issue Dec 30, 2019 · 3 comments · Fixed by #5599
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda @aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. in-progress This issue is being actively worked on. p1

Comments

@wcauchois
Copy link
Contributor

I'm trying to create an S3 bucket and set up an object created notification with a LambdaDestination. My stack looks like this (verbatim):

export class DeliveryStreamStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props: DeliveryStreamStackProps) {
    super(scope, id, props);

    const bucket = new s3.Bucket(this, 'Bucket');
    bucket.addObjectCreatedNotification(new s3n.LambdaDestination(
      lambda.Function.fromFunctionArn(this, 'FunctionArn', 'REDACTED_ARN')
    ));
  }
}

However, when I try to synthesize my application I get the following error:

$ yarn cdk synth DataPipelineDeliveryStream-production
yarn run v1.19.2
$ /Users/wcauchois/code/datapipeline/node_modules/.bin/cdk synth DataPipelineDeliveryStream-production

/Users/wcauchois/code/datapipeline/node_modules/@aws-cdk/core/lib/construct.ts:191
      throw new Error(`No child with id: '${id}'`);
            ^
Error: No child with id: 'AllowBucketNotificationsFromDataPipelineDeliveryStreamproductionBucketD6C74BCD'
    at ConstructNode.findChild (/Users/wcauchois/code/datapipeline/node_modules/@aws-cdk/core/lib/construct.ts:191:13)
    at LambdaDestination.bind (/Users/wcauchois/code/datapipeline/node_modules/@aws-cdk/aws-s3-notifications/lib/lambda.ts:26:37)
    at BucketNotifications.addNotification (/Users/wcauchois/code/datapipeline/node_modules/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts:56:32)
    at Bucket.addEventNotification (/Users/wcauchois/code/datapipeline/node_modules/@aws-cdk/aws-s3/lib/bucket.ts:1103:24)
    at Bucket.addObjectCreatedNotification (/Users/wcauchois/code/datapipeline/node_modules/@aws-cdk/aws-s3/lib/bucket.ts:1115:17)
    at new DeliveryStreamStack (/Users/wcauchois/code/datapipeline/cdk/stacks/deliverystream.ts:22:12)
    at Object.<anonymous> (/Users/wcauchois/code/datapipeline/cdk/app.ts:9:1)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Module.m._compile (/Users/wcauchois/code/datapipeline/node_modules/ts-node/src/index.ts:536:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:785:10)

I am using aws-cdk version 1.19.0. Any help on this issue would be appreciated!

@wcauchois wcauchois added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 30, 2019
@wcauchois
Copy link
Contributor Author

I looked into it a bit and I think the issue might be that on this line:

const permission = this.fn.node.findChild(permissionId) as CfnResource;

that findChild(permissionId) should be tryFindChild(permissionId). I'm not familiar enough with the code to know that for sure though.

@SomayaB SomayaB added @aws-cdk/aws-s3 Related to Amazon S3 @aws-cdk/aws-lambda Related to AWS Lambda labels Dec 30, 2019
@eladb
Copy link
Contributor

eladb commented Dec 31, 2019

I think you are correct. This should be tryFindChild. Would you like to try and submit a pull request with this fix?

@wcauchois
Copy link
Contributor Author

cool, i gave it a try here! #5599

(BTW, if this change merits any sort of thanks.. perhaps you could chime in on a recent CDK-related stackoverflow question i asked - https://stackoverflow.com/questions/59545731/how-to-execute-commands-needed-to-prepare-an-artifact 🙂)

@SomayaB SomayaB added in-progress This issue is being actively worked on. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 2, 2020
eladb pushed a commit that referenced this issue Jan 5, 2020
fixes #5592

Co-authored-by: Elad Ben-Israel <benisrae@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda @aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. 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