当我使用step函数调用API Gateway时,我填写了“Headers.$”:“$.input.headers”,但是当我测试它时,它给我could not be used to start the任务:每次[“标题”字段的值格式无效]
,
我试过这个
"input": {
"headers": {
"Authorization": "abcd",
"Content-Type": "application-json"
}
}
它不起作用,任何人都可以给我这个标题字段的示例吗?
非常感谢!
最佳答案
我遇到了同样的问题。我解决如下。
首先,我们不能使用 Authorization
header 和其他一些 header ,如 the note of this documentation 。所以我们应该使用自定义 header 。它映射到 API Gateway 中的 Authorization
header 。
接下来,根据我的尝试,我们可能应该在 Headers
的值中使用数组格式。
所以你可以写如下:
"input": {
"headers": {
"x-Authorization": ["abcd"],
"Content-Type": ["application-json"]
}
}
我使用intrinsic functions如下:
"Headers":{
"x-Authorization.$":"States.Array(States.Format('Bearer {}', $.SecretOutput.Token))"
}
最后,我们应该在 API Gateway 中设置两个配置。
- 设置请求参数映射以将
method.request.header.x-Authorization
映射到Authorization
header 。 documentation - 设置接受自定义请求 header
x-Authorization
。 documentation
关于amazon-web-services - 如何设置 Step 函数的 Headers.$ 输入来调用 api 网关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65623332/