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

标签 amazon-web-services aws-step-functions

当我使用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 中设置两个配置。

  1. 设置请求参数映射以将 method.request.header.x-Authorization 映射到 Authorization header 。 documentation
  2. 设置接受自定义请求 header x-Authorizationdocumentation

关于amazon-web-services - 如何设置 Step 函数的 Headers.$ 输入来调用 api 网关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65623332/

相关文章:

amazon-web-services - 无效资源和格式错误的策略错误 - aws cloudformation YAML

amazon-web-services - 与 AWS Step Functions 通信时出错

amazon-web-services - 启动 StepFunction 并退出不会触发执行

java - 如何在运行时从 DynamoDB 获取排序结果

amazon-web-services - AWS S3 存储桶策略允许从我的实例进行只读访问

python - 在 Amazon Elasticsearch Service 上建立索引 - 批量插入

amazon-web-services - 将无服务器 API 网关 URL 作为参数传递给同一堆栈中的 Lambda 函数

amazon-web-services - Terraform:如果目标是 aws_sfn_state_machine,则 aws_api_gateway_integration 的 uri 参数是什么

amazon-web-services - 选择 - 将输入中的值与空字符串进行比较

amazon-web-services - 使用 aws stepfunctions 的内部函数从拆分的字符串中获取值