Skip to content

Commit

Permalink
fix(s3n): s3n lambda destination works with function by arn (aws#5599)
Browse files Browse the repository at this point in the history
fixes aws#5592

Co-authored-by: Elad Ben-Israel <benisrae@amazon.com>
  • Loading branch information
wcauchois and Elad Ben-Israel committed Jan 5, 2020
1 parent e9ede13 commit 7ceee6d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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"
}
]
}
});
});

0 comments on commit 7ceee6d

Please sign in to comment.