From 382da6a9d13833561052ca7b1b4594095b2bae76 Mon Sep 17 00:00:00 2001 From: Sam Goodwin Date: Thu, 11 Apr 2019 10:44:29 -0700 Subject: [PATCH] fix(aws-lambda): fix circular dependency with lambda and codedeploy (#2236) --- .../lambda/integ.deployment-group.expected.json | 13 ++++++++++++- packages/@aws-cdk/aws-lambda/lib/alias.ts | 10 +++++++++- packages/@aws-cdk/aws-lambda/test/test.alias.ts | 13 ++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-codedeploy/test/lambda/integ.deployment-group.expected.json b/packages/@aws-cdk/aws-codedeploy/test/lambda/integ.deployment-group.expected.json index 6b6a4f5473809..27491e271ad0b 100644 --- a/packages/@aws-cdk/aws-codedeploy/test/lambda/integ.deployment-group.expected.json +++ b/packages/@aws-cdk/aws-codedeploy/test/lambda/integ.deployment-group.expected.json @@ -436,7 +436,18 @@ { "Name": "Resource", "Value": { - "Ref": "Alias325C5727" + "Fn::Join": [ + "", + [ + { + "Fn::GetAtt": [ + "Handler886CB40B", + "Arn" + ] + }, + ":alias" + ] + ] } } ], diff --git a/packages/@aws-cdk/aws-lambda/lib/alias.ts b/packages/@aws-cdk/aws-lambda/lib/alias.ts index 9a046e2422e10..b074878fd167d 100644 --- a/packages/@aws-cdk/aws-lambda/lib/alias.ts +++ b/packages/@aws-cdk/aws-lambda/lib/alias.ts @@ -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 * @@ -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', { @@ -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 }); diff --git a/packages/@aws-cdk/aws-lambda/test/test.alias.ts b/packages/@aws-cdk/aws-lambda/test/test.alias.ts index 1deb7d3ac00a8..1e340495f691b 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.alias.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.alias.ts @@ -161,7 +161,18 @@ export = { }, { Name: "Resource", Value: { - Ref: "Alias325C5727" + 'Fn::Join': [ + '', + [ + { + "Fn::GetAtt": [ + "MyLambdaCCE802FB", + "Arn" + ] + }, + ':prod' + ] + ] } }] }));