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

fix(s3-notifications): cannot use imported lambda ("fromArn") as a destination #5599

Merged
merged 2 commits into from
Jan 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-s3-notifications/lib/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class LambdaDestination implements s3.IBucketNotificationDestination {

// if we have a permission resource for this relationship, add it as a dependency
// to the bucket notifications resource, so it will be created first.
const permission = this.fn.node.findChild(permissionId) as CfnResource;
const permission = this.fn.node.tryFindChild(permissionId) as CfnResource | undefined;

return {
type: s3.BucketNotificationDestinationType.LAMBDA,
Expand Down
27 changes: 27 additions & 0 deletions packages/@aws-cdk/aws-s3-notifications/test/lambda/lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,30 @@ test('lambda as notification target', () => {
}
});
});

test('lambda as notification target specified by function arn', () => {
// GIVEN
const stack = new Stack();
const bucketA = new s3.Bucket(stack, 'MyBucket');
const fn = lambda.Function.fromFunctionArn(stack, 'MyFunction', 'arn:aws:lambda:us-east-1:123456789012:function:ProcessKinesisRecords');

// WHEN
bucketA.addObjectCreatedNotification(new s3n.LambdaDestination(fn), { suffix: '.png' });

// THEN
expect(stack).toHaveResource('Custom::S3BucketNotifications', {
NotificationConfiguration: {
LambdaFunctionConfigurations: [
{
Events: [ "s3:ObjectCreated:*" ],
Filter: {
Key: {
FilterRules: [ { Name: "suffix", Value: ".png" } ]
}
},
LambdaFunctionArn: "arn:aws:lambda:us-east-1:123456789012:function:ProcessKinesisRecords"
}
]
}
});
});