From 6b5ff997dbe76f009519459a07ef1aeb3dd394b1 Mon Sep 17 00:00:00 2001 From: Eugene Cheung Date: Thu, 10 Aug 2023 12:15:49 -0400 Subject: [PATCH] fix(step-functions): better infer name from Lambda function Fixes #274 --- .../StepFunctionLambdaIntegrationMonitoring.ts | 10 ++++++++-- ...tepFunctionLambdaIntegrationMonitoring.test.ts.snap | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/monitoring/aws-step-functions/StepFunctionLambdaIntegrationMonitoring.ts b/lib/monitoring/aws-step-functions/StepFunctionLambdaIntegrationMonitoring.ts index ac9fa8af..53bd8a58 100644 --- a/lib/monitoring/aws-step-functions/StepFunctionLambdaIntegrationMonitoring.ts +++ b/lib/monitoring/aws-step-functions/StepFunctionLambdaIntegrationMonitoring.ts @@ -3,6 +3,7 @@ import { HorizontalAnnotation, IWidget, } from "aws-cdk-lib/aws-cloudwatch"; +import { IFunction, CfnFunction } from "aws-cdk-lib/aws-lambda"; import { StepFunctionLambdaIntegrationMetricFactory, @@ -71,10 +72,10 @@ export class StepFunctionLambdaIntegrationMonitoring extends Monitoring { ) { super(scope, props); - const fallbackConstructName = props.lambdaFunction.functionName; const namingStrategy = new MonitoringNamingStrategy({ ...props, - fallbackConstructName, + namedConstruct: props.lambdaFunction, + fallbackConstructName: this.resolveFunctionName(props.lambdaFunction), }); this.title = namingStrategy.resolveHumanReadableName(); this.functionUrl = scope @@ -260,4 +261,9 @@ export class StepFunctionLambdaIntegrationMonitoring extends Monitoring { }), ]; } + + private resolveFunctionName(lambdaFunction: IFunction): string | undefined { + // try to take the name (if specified) instead of token + return (lambdaFunction.node.defaultChild as CfnFunction)?.functionName; + } } diff --git a/test/monitoring/aws-step-functions/__snapshots__/StepFunctionLambdaIntegrationMonitoring.test.ts.snap b/test/monitoring/aws-step-functions/__snapshots__/StepFunctionLambdaIntegrationMonitoring.test.ts.snap index 2a4b60af..7a44ec6e 100644 --- a/test/monitoring/aws-step-functions/__snapshots__/StepFunctionLambdaIntegrationMonitoring.test.ts.snap +++ b/test/monitoring/aws-step-functions/__snapshots__/StepFunctionLambdaIntegrationMonitoring.test.ts.snap @@ -146,7 +146,7 @@ Object { "Fn::Join": Array [ "", Array [ - "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### States Lambda Integration **[DummyLambdaIntegration](https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/", + "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### States Lambda Integration **[DummyLambda](https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/", Object { "Ref": "Function76856677", }, @@ -472,7 +472,7 @@ Object { "Fn::Join": Array [ "", Array [ - "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### States Lambda Integration **[DummyLambdaIntegration](https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/", + "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### States Lambda Integration **[DummyLambda](https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/", Object { "Ref": "Function76856677", }, @@ -651,7 +651,7 @@ Object { "Fn::Join": Array [ "", Array [ - "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### States Lambda Integration **[DummyLambdaIntegration](https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/", + "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### States Lambda Integration **[DummyLambda](https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/", Object { "Ref": "Function76856677", }, @@ -743,7 +743,7 @@ Object { "Fn::Join": Array [ "", Array [ - "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### States Lambda Integration **[DummyLambdaIntegration](https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/", + "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### States Lambda Integration **[DummyLambda](https://eu-west-1.console.aws.amazon.com/lambda/home?region=eu-west-1#/functions/", Object { "Ref": "Function76856677", },