Skip to content

Commit

Permalink
fix(aws-lambda): fix circular dependency with lambda and codedeploy (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Goodwin authored Apr 11, 2019
1 parent ad7425f commit 382da6a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,18 @@
{
"Name": "Resource",
"Value": {
"Ref": "Alias325C5727"
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"Handler886CB40B",
"Arn"
]
},
":alias"
]
]
}
}
],
Expand Down
10 changes: 9 additions & 1 deletion packages/@aws-cdk/aws-lambda/lib/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export interface AliasProps {
* A new alias to a particular version of a Lambda function.
*/
export class Alias extends FunctionBase {
/**
* Name of this alias.
*/
public readonly aliasName: string;
/**
* ARN of this alias
*
Expand All @@ -77,6 +81,7 @@ export class Alias extends FunctionBase {
constructor(scope: cdk.Construct, id: string, props: AliasProps) {
super(scope, id);

this.aliasName = props.aliasName;
this.underlyingLambda = props.version.lambda;

const alias = new CfnAlias(this, 'Resource', {
Expand Down Expand Up @@ -110,7 +115,10 @@ export class Alias extends FunctionBase {
return super.metric(metricName, {
dimensions: {
FunctionName: this.underlyingLambda.functionName,
Resource: this.functionArn
// construct the ARN from the underlying lambda so that alarms on an alias
// don't cause a circular dependency with CodeDeploy
// see: https://github.com/awslabs/aws-cdk/issues/2231
Resource: `${this.underlyingLambda.functionArn}:${this.aliasName}`
},
...props
});
Expand Down
13 changes: 12 additions & 1 deletion packages/@aws-cdk/aws-lambda/test/test.alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,18 @@ export = {
}, {
Name: "Resource",
Value: {
Ref: "Alias325C5727"
'Fn::Join': [
'',
[
{
"Fn::GetAtt": [
"MyLambdaCCE802FB",
"Arn"
]
},
':prod'
]
]
}
}]
}));
Expand Down

0 comments on commit 382da6a

Please sign in to comment.