Why aren't the HTTP headers passed from API Gateway to Step Functions?
I have an endpoint set up on API Gateway 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 in the logs after the request body has been transformed - before it executes the step function
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?
You should modify your mapping template to include the headers as part of the Input param as this is the only field which is passed to the Step Functions execution.
Something like this (did not actually try it so there may be some syntax mistakes):
#set($inputbody = $input.json('$'))
{
"method": "$context.httpMethod",
"input": {
"$util.escapeJavaScript($inputbody)",
"headers": {
#foreach($param in $input.params().header.keySet())
"$param": "$util.escapeJavaScript($input.params().header.get($param))"
#if($foreach.hasNext),#end
#end
}
}
"stateMachineArn": "MyStateMachineARN"
}
i have a similar problem. i haven't been able to pass headers from method-request to integration request without including them in the body(https://www.repost.aws/questions/QUKKPMq8TeQ5OTeuhAnu8G5g/pass-headers-from-clients-via-method-request-to-integration-request-with-body-intact-for-rest-api-in-aws-api-gateway). does this pass the body as is to the integration request including the headers?
Relevant questions
Trigger Step Function with API Gateway and use Fargate within Step Function?
asked a month agoI am having an issue in API Gateway that says " No integration defined for method" when I attempt to deploy
asked a month agoBuild a REST API with API Gateway private integration: Tutorial
Accepted Answerasked 2 months agoAPI Gateway HTTP + Lambda integration not enabling CORS
asked 3 months agoInvalid VpcLink id {xxxxxx} referenced in integration
asked 3 months agoPassing HTTP Headers from API Gateway HTTP API to Step Function?
asked a month agoWhy aren't the HTTP headers passed from API Gateway to Step Functions?
asked 5 months agopass headers from clients via method request to integration request with body intact for REST API in AWS API Gateway
Accepted Answerasked 3 months agoReturn HTML to browser from API Gateway using Lambda Proxy Integration
asked 3 years agoThrottlingException from Step Function triggered through API Endpoint
asked 2 years ago
The input to the Step Functions is only the string in the
input
property, so you will need to compose theinput
with both thebody
and theheaders
. At the core, API Gateway is calling StartExecution.