Skip to content

Commit bc40494

Browse files
authored
fix(lambda): Use Alias ARN directly (#2091)
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.
1 parent 7d4b9df commit bc40494

28 files changed

+308
-128
lines changed

packages/@aws-cdk/aws-apigateway/test/integ.restapi.books.expected.json

+41-11
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
"Properties": {
6666
"Action": "lambda:InvokeFunction",
6767
"FunctionName": {
68-
"Ref": "BooksHandler3EB83358"
68+
"Fn::GetAtt": [
69+
"BooksHandler3EB83358",
70+
"Arn"
71+
]
6972
},
7073
"Principal": "apigateway.amazonaws.com",
7174
"SourceArn": {
@@ -103,7 +106,10 @@
103106
"Properties": {
104107
"Action": "lambda:InvokeFunction",
105108
"FunctionName": {
106-
"Ref": "BooksHandler3EB83358"
109+
"Fn::GetAtt": [
110+
"BooksHandler3EB83358",
111+
"Arn"
112+
]
107113
},
108114
"Principal": "apigateway.amazonaws.com",
109115
"SourceArn": {
@@ -137,7 +143,10 @@
137143
"Properties": {
138144
"Action": "lambda:InvokeFunction",
139145
"FunctionName": {
140-
"Ref": "BooksHandler3EB83358"
146+
"Fn::GetAtt": [
147+
"BooksHandler3EB83358",
148+
"Arn"
149+
]
141150
},
142151
"Principal": "apigateway.amazonaws.com",
143152
"SourceArn": {
@@ -175,7 +184,10 @@
175184
"Properties": {
176185
"Action": "lambda:InvokeFunction",
177186
"FunctionName": {
178-
"Ref": "BooksHandler3EB83358"
187+
"Fn::GetAtt": [
188+
"BooksHandler3EB83358",
189+
"Arn"
190+
]
179191
},
180192
"Principal": "apigateway.amazonaws.com",
181193
"SourceArn": {
@@ -269,7 +281,10 @@
269281
"Properties": {
270282
"Action": "lambda:InvokeFunction",
271283
"FunctionName": {
272-
"Ref": "BookHandlerF9638A7A"
284+
"Fn::GetAtt": [
285+
"BookHandlerF9638A7A",
286+
"Arn"
287+
]
273288
},
274289
"Principal": "apigateway.amazonaws.com",
275290
"SourceArn": {
@@ -307,7 +322,10 @@
307322
"Properties": {
308323
"Action": "lambda:InvokeFunction",
309324
"FunctionName": {
310-
"Ref": "BookHandlerF9638A7A"
325+
"Fn::GetAtt": [
326+
"BookHandlerF9638A7A",
327+
"Arn"
328+
]
311329
},
312330
"Principal": "apigateway.amazonaws.com",
313331
"SourceArn": {
@@ -341,7 +359,10 @@
341359
"Properties": {
342360
"Action": "lambda:InvokeFunction",
343361
"FunctionName": {
344-
"Ref": "BookHandlerF9638A7A"
362+
"Fn::GetAtt": [
363+
"BookHandlerF9638A7A",
364+
"Arn"
365+
]
345366
},
346367
"Principal": "apigateway.amazonaws.com",
347368
"SourceArn": {
@@ -379,7 +400,10 @@
379400
"Properties": {
380401
"Action": "lambda:InvokeFunction",
381402
"FunctionName": {
382-
"Ref": "BookHandlerF9638A7A"
403+
"Fn::GetAtt": [
404+
"BookHandlerF9638A7A",
405+
"Arn"
406+
]
383407
},
384408
"Principal": "apigateway.amazonaws.com",
385409
"SourceArn": {
@@ -473,7 +497,10 @@
473497
"Properties": {
474498
"Action": "lambda:InvokeFunction",
475499
"FunctionName": {
476-
"Ref": "Hello4A628BD4"
500+
"Fn::GetAtt": [
501+
"Hello4A628BD4",
502+
"Arn"
503+
]
477504
},
478505
"Principal": "apigateway.amazonaws.com",
479506
"SourceArn": {
@@ -511,7 +538,10 @@
511538
"Properties": {
512539
"Action": "lambda:InvokeFunction",
513540
"FunctionName": {
514-
"Ref": "Hello4A628BD4"
541+
"Fn::GetAtt": [
542+
"Hello4A628BD4",
543+
"Arn"
544+
]
515545
},
516546
"Principal": "apigateway.amazonaws.com",
517547
"SourceArn": {
@@ -890,4 +920,4 @@
890920
}
891921
}
892922
}
893-
}
923+
}

packages/@aws-cdk/aws-apigateway/test/integ.restapi.expected.json

+25-7
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@
395395
"Properties": {
396396
"Action": "lambda:InvokeFunction",
397397
"FunctionName": {
398-
"Ref": "MyHandler6B74D312"
398+
"Fn::GetAtt": [
399+
"MyHandler6B74D312",
400+
"Arn"
401+
]
399402
},
400403
"Principal": "apigateway.amazonaws.com",
401404
"SourceArn": {
@@ -433,7 +436,10 @@
433436
"Properties": {
434437
"Action": "lambda:InvokeFunction",
435438
"FunctionName": {
436-
"Ref": "MyHandler6B74D312"
439+
"Fn::GetAtt": [
440+
"MyHandler6B74D312",
441+
"Arn"
442+
]
437443
},
438444
"Principal": "apigateway.amazonaws.com",
439445
"SourceArn": {
@@ -467,7 +473,10 @@
467473
"Properties": {
468474
"Action": "lambda:InvokeFunction",
469475
"FunctionName": {
470-
"Ref": "MyHandler6B74D312"
476+
"Fn::GetAtt": [
477+
"MyHandler6B74D312",
478+
"Arn"
479+
]
471480
},
472481
"Principal": "apigateway.amazonaws.com",
473482
"SourceArn": {
@@ -505,7 +514,10 @@
505514
"Properties": {
506515
"Action": "lambda:InvokeFunction",
507516
"FunctionName": {
508-
"Ref": "MyHandler6B74D312"
517+
"Fn::GetAtt": [
518+
"MyHandler6B74D312",
519+
"Arn"
520+
]
509521
},
510522
"Principal": "apigateway.amazonaws.com",
511523
"SourceArn": {
@@ -539,7 +551,10 @@
539551
"Properties": {
540552
"Action": "lambda:InvokeFunction",
541553
"FunctionName": {
542-
"Ref": "MyHandler6B74D312"
554+
"Fn::GetAtt": [
555+
"MyHandler6B74D312",
556+
"Arn"
557+
]
543558
},
544559
"Principal": "apigateway.amazonaws.com",
545560
"SourceArn": {
@@ -577,7 +592,10 @@
577592
"Properties": {
578593
"Action": "lambda:InvokeFunction",
579594
"FunctionName": {
580-
"Ref": "MyHandler6B74D312"
595+
"Fn::GetAtt": [
596+
"MyHandler6B74D312",
597+
"Arn"
598+
]
581599
},
582600
"Principal": "apigateway.amazonaws.com",
583601
"SourceArn": {
@@ -635,4 +653,4 @@
635653
}
636654
}
637655
}
638-
}
656+
}

packages/@aws-cdk/aws-apigateway/test/test.lambda-api.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,9 @@ export = {
126126
},
127127
":lambda:path/2015-03-31/functions/",
128128
{
129-
"Fn::GetAtt": [
130-
"handlerE1533BD5",
131-
"Arn"
132-
]
129+
"Ref": "alias68BF17F5"
133130
},
134-
":my-alias/invocations"
131+
"/invocations"
135132
]
136133
]
137134
}

packages/@aws-cdk/aws-codedeploy/test/lambda/integ.deployment-group.expected.json

+8-13
Original file line numberDiff line numberDiff line change
@@ -430,18 +430,13 @@
430430
{
431431
"Name": "FunctionName",
432432
"Value": {
433-
"Fn::Join": [
434-
"",
435-
[
436-
{
437-
"Fn::GetAtt": [
438-
"Handler886CB40B",
439-
"Arn"
440-
]
441-
},
442-
":alias"
443-
]
444-
]
433+
"Ref": "Handler886CB40B"
434+
}
435+
},
436+
{
437+
"Name": "Resource",
438+
"Value": {
439+
"Ref": "Alias325C5727"
445440
}
446441
}
447442
],
@@ -590,4 +585,4 @@
590585
"Description": "S3 key for asset version \"aws-cdk-codedeploy-lambda/PostHook/Code\""
591586
}
592587
}
593-
}
588+
}

packages/@aws-cdk/aws-cognito/test/test.user-pool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export = {
105105

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

packages/@aws-cdk/aws-ecs/test/ec2/integ.event-task.lit.expected.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,10 @@
490490
"Properties": {
491491
"Action": "lambda:InvokeFunction",
492492
"FunctionName": {
493-
"Ref": "EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E"
493+
"Fn::GetAtt": [
494+
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E",
495+
"Arn"
496+
]
494497
},
495498
"Principal": "sns.amazonaws.com",
496499
"SourceArn": {
@@ -1160,4 +1163,4 @@
11601163
"Description": "S3 key for asset version \"aws-ecs-integ-ecs/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\""
11611164
}
11621165
}
1163-
}
1166+
}

packages/@aws-cdk/aws-ecs/test/ec2/integ.event-task.lit.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import events = require('@aws-cdk/aws-events');
33
import cdk = require('@aws-cdk/cdk');
44
import ecs = require('../../lib');
55

6+
import path = require('path');
7+
68
const app = new cdk.App();
79

810
class EventStack extends cdk.Stack {
@@ -20,7 +22,9 @@ class EventStack extends cdk.Stack {
2022
// Create a Task Definition for the container to start
2123
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');
2224
taskDefinition.addContainer('TheContainer', {
23-
image: ecs.ContainerImage.fromAsset(this, 'EventImage', { directory: 'eventhandler-image' }),
25+
image: ecs.ContainerImage.fromAsset(this, 'EventImage', {
26+
directory: path.resolve(__dirname, '..', 'eventhandler-image')
27+
}),
2428
memoryLimitMiB: 256,
2529
logging: new ecs.AwsLogDriver(this, 'TaskLogging', { streamPrefix: 'EventDemo' })
2630
});

packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-awsvpc-nw.expected.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,10 @@
646646
"Properties": {
647647
"Action": "lambda:InvokeFunction",
648648
"FunctionName": {
649-
"Ref": "EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E"
649+
"Fn::GetAtt": [
650+
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E",
651+
"Arn"
652+
]
650653
},
651654
"Principal": "sns.amazonaws.com",
652655
"SourceArn": {

packages/@aws-cdk/aws-ecs/test/ec2/integ.lb-bridge-nw.expected.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,10 @@
667667
"Properties": {
668668
"Action": "lambda:InvokeFunction",
669669
"FunctionName": {
670-
"Ref": "EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E"
670+
"Fn::GetAtt": [
671+
"EcsClusterDefaultAutoScalingGroupDrainECSHookFunctionE17A5F5E",
672+
"Arn"
673+
]
671674
},
672675
"Principal": "sns.amazonaws.com",
673676
"SourceArn": {

packages/@aws-cdk/aws-lambda-event-sources/test/integ.s3.expected.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
"Properties": {
6666
"Action": "lambda:InvokeFunction",
6767
"FunctionName": {
68-
"Ref": "FC4345940"
68+
"Fn::GetAtt": [
69+
"FC4345940",
70+
"Arn"
71+
]
6972
},
7073
"Principal": "s3.amazonaws.com",
7174
"SourceAccount": {
@@ -205,4 +208,4 @@
205208
}
206209
}
207210
}
208-
}
211+
}

packages/@aws-cdk/aws-lambda-event-sources/test/integ.sns.expected.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@
8080
"Properties": {
8181
"Action": "lambda:InvokeFunction",
8282
"FunctionName": {
83-
"Ref": "FC4345940"
83+
"Fn::GetAtt": [
84+
"FC4345940",
85+
"Arn"
86+
]
8487
},
8588
"Principal": "sns.amazonaws.com",
8689
"SourceArn": {
@@ -92,4 +95,4 @@
9295
"Type": "AWS::SNS::Topic"
9396
}
9497
}
95-
}
98+
}

packages/@aws-cdk/aws-lambda-event-sources/test/integ.sqs.expected.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@
114114
"Type": "AWS::SQS::Queue"
115115
}
116116
}
117-
}
117+
}

packages/@aws-cdk/aws-lambda-event-sources/test/test.sns.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export = {
2121
expect(stack).to(haveResource('AWS::Lambda::Permission', {
2222
"Action": "lambda:InvokeFunction",
2323
"FunctionName": {
24-
"Ref": "Fn9270CBC0"
24+
"Fn::GetAtt": [
25+
"Fn9270CBC0",
26+
"Arn"
27+
]
2528
},
2629
"Principal": "sns.amazonaws.com",
2730
"SourceArn": {

0 commit comments

Comments
 (0)