- 最新
- 最多得票
- 最多評論
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?
I've gotten this to work for single request headers, but this only works if you know the key of the header in advance. For example:
#set($body = $input.json('$'))
#set($token = $input.params().header.get('x-api-token'))
{
"input":"{\"token\":\"$util.escapeJavaScript($token).replaceAll("\\\\'", "'")\",\"body\":$util.escapeJavaScript($body).replaceAll("\\\\'", "'")}",
"stateMachineArn": "arn:aws:states:eu-central-1:xxxx:stateMachine:xxxx"
}
Here, 'x-api-token' is the key of the example HTTP header. We set the value of this header in the JSON input object that is passed into the state machine. The request body is set as well.
It doesn't match OP's question exactly, but might still be useful for someone searching on this topic.
If you want to deploy this via CDK, you'll need to escape all backlashes correctly:
#set($body = $input.json('$')) #set($x-api-token = $input.params().header.get('x-api-token')) { "input":"{\\\"x-api-token\\\":\\\"$util.escapeJavaScript($x-api-token).replaceAll.replaceAll("\\\\'", "'")\\\",\\\"body\\\":$util.escapeJavaScript($body).replaceAll("\\\\'", "'")}", "stateMachineArn": "${stateMachineArn}" }
This answer don't work anymore, it returns: Endpoint response body before transformations: {"__type":"com.amazon.coral.service#SerializationException"}
This is quite frustrating, to be honest. There should be a way to pass all parameters EASILY to the step functions without this much hassle.
相關內容
- AWS 官方已更新 2 年前
- AWS 官方已更新 1 年前
- AWS 官方已更新 1 年前
- AWS 官方已更新 2 年前
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.