Skip to content

Commit

Permalink
fix(lambda): Use Alias ARN directly (#2091)
Browse files Browse the repository at this point in the history
Use the Alias resource's ARN instead of building one using `Fn::Join`, so
that referencing the ARN implies a dependency on the alias.

Additionally, forward the underlying function's role to the Alias' role
property.
  • Loading branch information
RomainMuller authored Mar 28, 2019
1 parent 7d4b9df commit bc40494
Show file tree
Hide file tree
Showing 28 changed files with 308 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "BooksHandler3EB83358"
"Fn::GetAtt": [
"BooksHandler3EB83358",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -103,7 +106,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "BooksHandler3EB83358"
"Fn::GetAtt": [
"BooksHandler3EB83358",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -137,7 +143,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "BooksHandler3EB83358"
"Fn::GetAtt": [
"BooksHandler3EB83358",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -175,7 +184,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "BooksHandler3EB83358"
"Fn::GetAtt": [
"BooksHandler3EB83358",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -269,7 +281,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "BookHandlerF9638A7A"
"Fn::GetAtt": [
"BookHandlerF9638A7A",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -307,7 +322,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "BookHandlerF9638A7A"
"Fn::GetAtt": [
"BookHandlerF9638A7A",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -341,7 +359,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "BookHandlerF9638A7A"
"Fn::GetAtt": [
"BookHandlerF9638A7A",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -379,7 +400,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "BookHandlerF9638A7A"
"Fn::GetAtt": [
"BookHandlerF9638A7A",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -473,7 +497,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "Hello4A628BD4"
"Fn::GetAtt": [
"Hello4A628BD4",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -511,7 +538,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "Hello4A628BD4"
"Fn::GetAtt": [
"Hello4A628BD4",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -890,4 +920,4 @@
}
}
}
}
}
32 changes: 25 additions & 7 deletions packages/@aws-cdk/aws-apigateway/test/integ.restapi.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "MyHandler6B74D312"
"Fn::GetAtt": [
"MyHandler6B74D312",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -433,7 +436,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "MyHandler6B74D312"
"Fn::GetAtt": [
"MyHandler6B74D312",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -467,7 +473,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "MyHandler6B74D312"
"Fn::GetAtt": [
"MyHandler6B74D312",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -505,7 +514,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "MyHandler6B74D312"
"Fn::GetAtt": [
"MyHandler6B74D312",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -539,7 +551,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "MyHandler6B74D312"
"Fn::GetAtt": [
"MyHandler6B74D312",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -577,7 +592,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "MyHandler6B74D312"
"Fn::GetAtt": [
"MyHandler6B74D312",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -635,4 +653,4 @@
}
}
}
}
}
7 changes: 2 additions & 5 deletions packages/@aws-cdk/aws-apigateway/test/test.lambda-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,9 @@ export = {
},
":lambda:path/2015-03-31/functions/",
{
"Fn::GetAtt": [
"handlerE1533BD5",
"Arn"
]
"Ref": "alias68BF17F5"
},
":my-alias/invocations"
"/invocations"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,18 +430,13 @@
{
"Name": "FunctionName",
"Value": {
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"Handler886CB40B",
"Arn"
]
},
":alias"
]
]
"Ref": "Handler886CB40B"
}
},
{
"Name": "Resource",
"Value": {
"Ref": "Alias325C5727"
}
}
],
Expand Down Expand Up @@ -590,4 +585,4 @@
"Description": "S3 key for asset version \"aws-cdk-codedeploy-lambda/PostHook/Code\""
}
}
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cognito/test/test.user-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export = {

// THEN
expect(stack).to(haveResourceLike('AWS::Lambda::Permission', {
FunctionName: fn.node.resolve(fn.functionName),
FunctionName: fn.node.resolve(fn.functionArn),
Principal: 'cognito-idp.amazonaws.com'
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E"
"Fn::GetAtt": [
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E",
"Arn"
]
},
"Principal": "sns.amazonaws.com",
"SourceArn": {
Expand Down Expand Up @@ -1160,4 +1163,4 @@
"Description": "S3 key for asset version \"aws-ecs-integ-ecs/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\""
}
}
}
}
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-ecs/test/ec2/integ.event-task.lit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import events = require('@aws-cdk/aws-events');
import cdk = require('@aws-cdk/cdk');
import ecs = require('../../lib');

import path = require('path');

const app = new cdk.App();

class EventStack extends cdk.Stack {
Expand All @@ -20,7 +22,9 @@ class EventStack extends cdk.Stack {
// Create a Task Definition for the container to start
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
taskDefinition.addContainer('TheContainer', {
image: ecs.ContainerImage.fromAsset(this, 'EventImage', { directory: 'eventhandler-image' }),
image: ecs.ContainerImage.fromAsset(this, 'EventImage', {
directory: path.resolve(__dirname, '..', 'eventhandler-image')
}),
memoryLimitMiB: 256,
logging: new ecs.AwsLogDriver(this, 'TaskLogging', { streamPrefix: 'EventDemo' })
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E"
"Fn::GetAtt": [
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E",
"Arn"
]
},
"Principal": "sns.amazonaws.com",
"SourceArn": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E"
"Fn::GetAtt": [
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E",
"Arn"
]
},
"Principal": "sns.amazonaws.com",
"SourceArn": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "FC4345940"
"Fn::GetAtt": [
"FC4345940",
"Arn"
]
},
"Principal": "s3.amazonaws.com",
"SourceAccount": {
Expand Down Expand Up @@ -205,4 +208,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "FC4345940"
"Fn::GetAtt": [
"FC4345940",
"Arn"
]
},
"Principal": "sns.amazonaws.com",
"SourceArn": {
Expand All @@ -92,4 +95,4 @@
"Type": "AWS::SNS::Topic"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@
"Type": "AWS::SQS::Queue"
}
}
}
}
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-lambda-event-sources/test/test.sns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export = {
expect(stack).to(haveResource('AWS::Lambda::Permission', {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "Fn9270CBC0"
"Fn::GetAtt": [
"Fn9270CBC0",
"Arn"
]
},
"Principal": "sns.amazonaws.com",
"SourceArn": {
Expand Down
Loading

0 comments on commit bc40494

Please sign in to comment.