'Why aren't HTTP Headers passed from AWS API Gateway to Step functions

I have an api gateway set up with integration to a step function - the integration is working well and my function is executed. However I have a need to access the headers on the initial request to the api gateway (as they need to be passed on to an API call made by one of the steps in the step function) I've added the http headers to the API Gateway Method Request and also done this in the HTTP Headers section of the Integration Request, then in the mapping template I have

#set($inputbody = $input.json('$'))
{
   "method": "$context.httpMethod",
   "input": "$util.escapeJavaScript($inputbody)",
   "stateMachineArn": "MyStateMachineARN",
   "headers": {
        #foreach($param in $input.params().header.keySet())
        "$param": "$util.escapeJavaScript($input.params().header.get($param))"
        #if($foreach.hasNext),#end
        #end
    }
}

When I test this I see the headers after the request body has been transformed - before it executes the step function

Thu Dec 23 09:35:28 UTC 2021 : Endpoint request body after transformations: {
   "method": "POST",
   "input": "{\"surname\":\"TESTSURNAME\"}",
   "stateMachineArn": "MyStateMachineARN",
   "headers": {
                "HeaderA": "ValueA"
        ,                "HeaderB": "ValueB"
                    }
}

But in the step functions I am struggling to see the headers - the input I can see at the start of the execution is only

{
   "surname::"TESTSURNAME"
}

I have inputPath set to $ and the same for the payload.

All the suggestions I've found online point to the mapping template but I can not get it to work - any ideas what I'm doing wrong?



Solution 1:[1]

The API Gateway -> Step Function integration uses StartExecution as the action for the integration. Checking the documentation for StartExecution request syntax, it turns out that headers is unfortunately not one of the allowable fields that can be passed. To pass the headers in it looks like you would need to add them onto the input.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 knueser