then context injection for the Step Function will fail with the error:
[Error] Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: Cannot have both the field 'CONTEXT.$' and the field 'CONTEXT' at the same time at /States/Step Functions StartExecution/Parameters'. Failed to inject context into lambda functions' payload of arn:aws:states:sa-east-1:425362996713:stateMachine:YimingTestExpressStateMachine2
This is because our instrumentation code will add a field "CONTEXT.$": ..., which duplicates with "CONTEXT": .... Right now we only check for custom "CONTEXT.$": ... (with $, i.e. using JSONPath) but don't check for custom "CONTEXT": ....
What
Also skip context injection when a custom "CONTEXT": ... field is used (without $)
Testing
Automated testing
Pass the added test, which would fail without the changes on helpers.ts
Manual testing
Steps:
change the CONTEXT field of a Lambda function to what's shown in "Problem" section
The behavior will be changed soon: we will soon allow custom CONTEXT field as long as it doesn't contain Execution or State field inside. But I want to first merge this PR to make the existing behavior more clear, so the changes in future PRs will be more clear so the PRs will be easier to review.
Review checklist
[x] Feature or bugfix MUST have appropriate tests (unit, integration)
Problem
If a Lambda function in a State Machine has a custom
Payload
defined using"Payload": ...
, e.g.,then context injection for the Step Function will fail with the error:
This is because our instrumentation code will add a field
"CONTEXT.$": ...
, which duplicates with"CONTEXT": ...
. Right now we only check for custom"CONTEXT.$": ...
(with$
, i.e. using JSONPath) but don't check for custom"CONTEXT": ...
.What
Also skip context injection when a custom
"CONTEXT": ...
field is used (without$
)Testing
Automated testing
Pass the added test, which would fail without the changes on
helpers.ts
Manual testing
Steps:
CONTEXT
field of a Lambda function to what's shown in "Problem" sectiondatadog-ci stepfunctions instrument
Result: a warning is printed as expected
Notes
CONTEXT
field as long as it doesn't containExecution
orState
field inside. But I want to first merge this PR to make the existing behavior more clear, so the changes in future PRs will be more clear so the PRs will be easier to review.Review checklist