Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-lambda): fix circular dependency with lambda and codedeploy #2236

Merged
merged 2 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide some reasoning for why we are doing it like this here. Reference an issue?

},
...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