Skip to content

Commit ab22198

Browse files
author
Eugene Cheung
authored
fix(step-functions): Infer construct fallback name from Lambda function (#407)
Fixes #274 Use the same strategy that [we use for vanilla Lambda](https://github.com/cdklabs/cdk-monitoring-constructs/blob/cec84dba29fa60d55fcbc23ae71d13c32246182d/lib/monitoring/aws-lambda/LambdaFunctionMonitoring.ts#L169). --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent cec84db commit ab22198

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/monitoring/aws-step-functions/StepFunctionLambdaIntegrationMonitoring.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
HorizontalAnnotation,
44
IWidget,
55
} from "aws-cdk-lib/aws-cloudwatch";
6+
import { IFunction, CfnFunction } from "aws-cdk-lib/aws-lambda";
67

78
import {
89
StepFunctionLambdaIntegrationMetricFactory,
@@ -71,10 +72,10 @@ export class StepFunctionLambdaIntegrationMonitoring extends Monitoring {
7172
) {
7273
super(scope, props);
7374

74-
const fallbackConstructName = props.lambdaFunction.functionName;
7575
const namingStrategy = new MonitoringNamingStrategy({
7676
...props,
77-
fallbackConstructName,
77+
namedConstruct: props.lambdaFunction,
78+
fallbackConstructName: this.resolveFunctionName(props.lambdaFunction),
7879
});
7980
this.title = namingStrategy.resolveHumanReadableName();
8081
this.functionUrl = scope
@@ -260,4 +261,9 @@ export class StepFunctionLambdaIntegrationMonitoring extends Monitoring {
260261
}),
261262
];
262263
}
264+
265+
private resolveFunctionName(lambdaFunction: IFunction): string | undefined {
266+
// try to take the name (if specified) instead of token
267+
return (lambdaFunction.node.defaultChild as CfnFunction)?.functionName;
268+
}
263269
}

test/monitoring/aws-step-functions/__snapshots__/StepFunctionLambdaIntegrationMonitoring.test.ts.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)