diff --git a/packages/@aws-cdk/triggers/test/integ.triggers.js.snapshot/MyStack.template.json b/packages/@aws-cdk/triggers/test/integ.triggers.js.snapshot/MyStack.template.json index 093720853cf8c..4923d463c8cca 100644 --- a/packages/@aws-cdk/triggers/test/integ.triggers.js.snapshot/MyStack.template.json +++ b/packages/@aws-cdk/triggers/test/integ.triggers.js.snapshot/MyStack.template.json @@ -69,7 +69,7 @@ ] }, "HandlerArn": { - "Ref": "MyTriggerFunctionCurrentVersion61957CE160cd5b4c06c4d00191dc10a647ea0777" + "Ref": "MyTriggerFunctionCurrentVersion61957CE160cd5b4c06c4d00191dc10a647ea0777" }, "InvocationType": "RequestResponse", "Timeout": { @@ -87,7 +87,7 @@ "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" }, - "MyTriggerFunctionCurrentVersion61957CE160cd5b4c06c4d00191dc10a647ea0777": { + "MyTriggerFunctionCurrentVersion61957CE160cd5b4c06c4d00191dc10a647ea0777": { "Type": "AWS::Lambda::Version", "Properties": { "FunctionName": { @@ -143,6 +143,28 @@ } ] }, + { + "Effect": "Allow", + "Action": [ + "lambda:InvokeFunction" + ], + "Resource": [ + { + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "MyLambdaFunction67CCA873", + "Arn" + ] + }, + ":*" + ] + ] + } + ] + }, { "Effect": "Allow", "Action": [ @@ -195,7 +217,7 @@ "AWSCDKTriggerCustomResourceProviderCustomResourceProviderRoleE18FAF0A" ] }, - "MySecondFunctionServiceRole5B930841": { + "MyLambdaFunctionServiceRole313A4D46": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -226,26 +248,35 @@ ] } }, - "MySecondFunction0F0B51EB": { + "MyLambdaFunction67CCA873": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "ZipFile": "exports.handler = function() { console.log(\"hello\"); };" + "ZipFile": "exports.handler = function() { await setTimeout(3*60*1000, \"hi\"); };" }, "Role": { "Fn::GetAtt": [ - "MySecondFunctionServiceRole5B930841", + "MyLambdaFunctionServiceRole313A4D46", "Arn" ] }, "Handler": "index.handler", - "Runtime": "nodejs16.x" + "Runtime": "nodejs16.x", + "Timeout": 900 }, "DependsOn": [ - "MySecondFunctionServiceRole5B930841" + "MyLambdaFunctionServiceRole313A4D46" ] }, - "MySecondFunctionTrigger8C61EC28": { + "MyLambdaFunctionCurrentVersion4FAB80ECdc4d4e257bb2b44c9c4b9231f0d16f4c": { + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MyLambdaFunction67CCA873" + } + } + }, + "MyTrigger": { "Type": "Custom::Trigger", "Properties": { "ServiceToken": { @@ -255,21 +286,19 @@ ] }, "HandlerArn": { - "Ref": "MySecondFunctionCurrentVersion7D497B5D173a4bb1f758991022ea97d651403362" - } + "Ref": "MyLambdaFunctionCurrentVersion4FAB80ECdc4d4e257bb2b44c9c4b9231f0d16f4c" + }, + "InvocationType": "Event", + "Timeout": 60000 }, + "DependsOn": [ + "Topic198E71B3E", + "Topic269377B75" + ], "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" }, - "MySecondFunctionCurrentVersion7D497B5D173a4bb1f758991022ea97d651403362": { - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MySecondFunction0F0B51EB" - } - } - }, - "MyLambdaFunctionServiceRole313A4D46": { + "MySecondFunctionServiceRole5B930841": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -300,35 +329,26 @@ ] } }, - "MyLambdaFunction67CCA873": { + "MySecondFunction0F0B51EB": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "ZipFile": "exports.handler = function() { await setTimeout(3*60*1000, \"hi\"); };" + "ZipFile": "exports.handler = function() { console.log(\"hello\"); };" }, "Role": { "Fn::GetAtt": [ - "MyLambdaFunctionServiceRole313A4D46", + "MySecondFunctionServiceRole5B930841", "Arn" ] }, "Handler": "index.handler", - "Runtime": "nodejs16.x", - "Timeout": 900 + "Runtime": "nodejs16.x" }, "DependsOn": [ - "MyLambdaFunctionServiceRole313A4D46" + "MySecondFunctionServiceRole5B930841" ] }, - "MyLambdaFunctionCurrentVersion4FAB80ECdc4d4e257bb2b44c9c4b9231f0d16f4c": { - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MyLambdaFunction67CCA873" - } - } - }, - "MyTrigger": { + "MySecondFunctionTrigger8C61EC28": { "Type": "Custom::Trigger", "Properties": { "ServiceToken": { @@ -338,17 +358,28 @@ ] }, "HandlerArn": { - "Ref": "MyLambdaFunctionCurrentVersion4FAB80ECdc4d4e257bb2b44c9c4b9231f0d16f4c" + "Ref": "MySecondFunctionCurrentVersion7D497B5D173a4bb1f758991022ea97d651403362" }, - "InvocationType": "Event", - "Timeout": 60000 + "InvocationType": "RequestResponse", + "Timeout": { + "amount": 2, + "unit": { + "label": "minutes", + "isoLabel": "M", + "inMillis": 60000 + } + } }, - "DependsOn": [ - "Topic198E71B3E", - "Topic269377B75" - ], "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" + }, + "MySecondFunctionCurrentVersion7D497B5D173a4bb1f758991022ea97d651403362": { + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MySecondFunction0F0B51EB" + } + } } }, "Parameters": { diff --git a/packages/@aws-cdk/triggers/test/trigger-handler.test.ts b/packages/@aws-cdk/triggers/test/trigger-handler.test.ts index bbfe4f2062748..09a4d77a657b5 100644 --- a/packages/@aws-cdk/triggers/test/trigger-handler.test.ts +++ b/packages/@aws-cdk/triggers/test/trigger-handler.test.ts @@ -41,14 +41,14 @@ test('Create', async () => { await lambda.handler({ RequestType: 'Create', ...mockRequest }); expect(invokeMock).toBeCalledTimes(1); - expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn }); + expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn, InvocationType: 'Event' }); }); test('Update', async () => { await lambda.handler({ RequestType: 'Update', PhysicalResourceId: 'PRID', OldResourceProperties: {}, ...mockRequest }); expect(invokeMock).toBeCalledTimes(1); - expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn }); + expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn, InvocationType: 'Event' }); }); test('Delete - handler not called', async () => { @@ -66,7 +66,7 @@ test('non-200 status code throws an error', async () => { .toMatchObject({ message: 'Trigger handler failed with status code 500' }); expect(invokeMock).toBeCalledTimes(1); - expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn }); + expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn, InvocationType: 'Event' }); }); test('retry with access denied exception', async () => { @@ -83,7 +83,7 @@ test('retry with access denied exception', async () => { await response; expect(invokeMock).toBeCalledTimes(2); - expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn }); + expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn, InvocationType: 'Event' }); }); test('throws an error for other exceptions', async () => { @@ -96,7 +96,7 @@ test('throws an error for other exceptions', async () => { .toThrow(); expect(invokeMock).toBeCalledTimes(1); - expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn }); + expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn, InvocationType: 'Event' }); }); describe('function error', () => { @@ -113,7 +113,7 @@ describe('function error', () => { .toMatchObject({ message: expectedError }); expect(invokeMock).toBeCalledTimes(1); - expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn }); + expect(invokeMock).toBeCalledWith({ FunctionName: handlerArn, InvocationType: 'Event' }); }; };