如何设置 Step 函数的 Headers.$ 输入来调用 api 网关?

Ale*_*lex 2 amazon-web-services aws-step-functions

当我使用step函数调用API网关时,我填写了“Headers.$”:“$.input.headers”,但是当我测试它时,它could not be used to start the Task: [The value of the field 'Headers' has an invalid format]每次都会给我,我尝试了这个

"input": {
        "headers": {
            "Authorization": "abcd",
            "Content-Type": "application-json"
        }
    }
Run Code Online (Sandbox Code Playgroud)

它不起作用,任何人都可以给我这个标题字段的示例吗?

万分感激!

yam*_*tsu 5

我遇到了同样的问题。我解决如下。

首先,我们不能使用Authorizationheader和其他一些header作为本文档的注释。所以我们应该使用自定义标头。它映射到AuthorizationAPI网关中的标头。

接下来,根据我的尝试,我们可能应该在 的值中使用数组格式Headers。所以你可以写如下:

"input": {
  "headers": {
    "x-Authorization": ["abcd"],
    "Content-Type": ["application-json"]
  }
}
Run Code Online (Sandbox Code Playgroud)

我使用内部函数如下:

"Headers":{
  "x-Authorization.$":"States.Array(States.Format('Bearer {}', $.SecretOutput.Token))"
}
Run Code Online (Sandbox Code Playgroud)

最后,我们应该在 API Gateway 中设置两个配置。

  1. 设置请求参数映射以映射method.request.header.x-AuthorizationAuthorization标头。文档
  2. 设置接受自定义请求标头x-Authorization文档