Skip to content

Commit ce08853

Browse files
authored
fix(lambda): generate correct metrics for aliases (#3728)
Lambda supports metrics on individual aliases by specifying the metric dimensions with `FunctionName` set to the underlying function's `Name`, and `ResourceName` set to the qualified function `Name` (i.e: `FunctionName:aliasName`). The previous iteration of this code used the function's ARN instead of it's name, resulting in incorrect metrics. Fixes #3724
1 parent f003dcc commit ce08853

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,7 @@
410410
"",
411411
[
412412
{
413-
"Fn::GetAtt": [
414-
"Handler886CB40B",
415-
"Arn"
416-
]
413+
"Ref": "Handler886CB40B"
417414
},
418415
":alias"
419416
]
@@ -589,4 +586,4 @@
589586
"Description": "Artifact hash for asset \"aws-cdk-codedeploy-lambda/PostHook/Code\""
590587
}
591588
}
592-
}
589+
}

packages/@aws-cdk/aws-lambda/lib/alias.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ export class Alias extends QualifiedFunctionBase implements IAlias {
156156
return super.metric(metricName, {
157157
dimensions: {
158158
FunctionName: this.lambda.functionName,
159-
// construct the ARN from the underlying lambda so that alarms on an alias
159+
// construct the name from the underlying lambda so that alarms on an alias
160160
// don't cause a circular dependency with CodeDeploy
161161
// see: https://github.com/aws/aws-cdk/issues/2231
162-
Resource: `${this.lambda.functionArn}:${this.aliasName}`
162+
Resource: `${this.lambda.functionName}:${this.aliasName}`
163163
},
164164
...props
165165
});

packages/@aws-cdk/aws-lambda/test/test.alias.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,7 @@ export = {
187187
'Fn::Join': [
188188
'',
189189
[
190-
{
191-
"Fn::GetAtt": [
192-
"MyLambdaCCE802FB",
193-
"Arn"
194-
]
195-
},
190+
{ Ref: "MyLambdaCCE802FB" },
196191
':prod'
197192
]
198193
]

0 commit comments

Comments
 (0)