DataDog / serverless-plugin-datadog

Serverless plugin to automagically instrument your Lambda functions with Datadog
Apache License 2.0
96 stars 49 forks source link

feat: Support sfn->Lambda context injection when no Payload exists (case 1) #528

Closed lym953 closed 2 months ago

lym953 commented 2 months ago

Current behavior:

In the Lambda step definition,

What does this PR do?

Change context injection behavior so that if Payload.$ or Payload don't exist, then inject context using:

$$['Execution', 'State', 'StateMachine']

This corresponds to Case 1 in the design doc Fixing Step Function Instrumentation

Motivation

Testing Guidelines

Automated tests

Passed the existing and added tests

Manual tests

Steps
  1. Create a State Machine with a Lambda step which has no Payload or Payload.$

    InvokeLambdaStep:
    Type: Task
    Resource: arn:aws:states:::lambda:invoke
    Parameters:
    FunctionName:
      Fn::GetAtt: [yiming_plugin_hello, Arn]
    # Payload.$: $
    End: true
  2. Run serverless deploy.

  3. Check the State Machine definition in AWS UI

Result

Context was injected as expected:

    "InvokeLambdaStep": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": {
        "FunctionName": "arn:aws:lambda:sa-east-1:425362996713:function:yiming-serverless-demo-dev-yiming_plugin_hello",
        "Payload.$": "$$['Execution', 'State', 'StateMachine']"
      },
      "End": true
    }

Additional Notes

Types of changes

Check all that apply

lym953 commented 2 months ago

/merge

dd-devflow[bot] commented 2 months ago

:steam_locomotive: MergeQueue: pull request added to the queue

The median merge time in main is 2m.

Use /merge -c to cancel this operation!