Repository: cdklabs/cdk-monitoring-constructs (language: python)

Issue:
SFM Lambda Integration naming should have the same strategy as normal Lambda Function
### Version

v1.28.1

### Steps and/or minimal code example to reproduce

When creating a monitoring segment for a Lambda Integration in a Step Function Machine, the following code should suffice to add it:

```typescript
let monitoring = new MonitoringFacade(this, "MyMonitoring")
  // ...
  .monitorStepFunctionLambdaIntegration({
    lambdaFunction: anyLambdaFunction,
    humanReadableName: "Some Step"
  });
```

### Expected behavior

The segment gets added successfully to the Dashboard.

### Actual behavior

CDK fails to synthesize, and raises the following exception:

> Error: Insufficient information provided for naming the alarms and/or monitoring section: Please provide alarmFriendlyName, humanReadableName, or namedConstruct as a fallback

### Other details

After investigating a bit the root cause, it seems like the props sent to the `MonitoringNamingStrategy` to create such resource are not really correct.

For Lambda Integration in Step Function Machines ([StepFunctionLambdaIntegrationMonitoring.ts#L74](https://github.com/cdklabs/cdk-monitoring-constructs/blob/main/lib/monitoring/aws-step-functions/StepFunctionLambdaIntegrationMonitoring.ts#L74)), they are created like this:

```typescript
const namingStrategy = new MonitoringNamingStrategy({
  ...props,
  fallbackConstructName: props.lambdaFunction.functionName,
});
```

However, for a standard Lambda Function ([LambdaFunctionMonitoring.ts#L169](https://github.com/cdklabs/cdk-monitoring-constructs/blob/main/lib/monitoring/aws-lambda/LambdaFunctionMonitoring.ts#L169)), they are like this:

```typescript
this.namingStrategy = new MonitoringNamingStrategy({
  ...props,
  namedConstruct: props.lambdaFunction,
  fallbackConstructName: this.resolveFunctionName(props.lambdaFunction),
});
```

As technically the created Monitoring segment for Lambda Integration and Lambda Function should behave in the same way (they are both monitoring Lambda functions), I believe the Lambda Integration SFM should be updated to be the same one as for Lambda Function.


Discussion / hints:
Any update on that? Faced the same issue here

Fix patch:
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;
+  }
 }


Test patch:
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",
               },