如何在 HTTP 集成 WebSocket api 网关 AWS 中添加请求标头参数

问题描述 投票:0回答:1

我是 AWS 新手。我想将标头参数添加到我的 HTTP 请求中。我在 CloudShell 中尝试了以下命令,但它不起作用。

aws apigatewayv2 update-integration --integration-id xxx --api-id xxxxx --request-parameters 'integration.request.header.Some-Header-Param'= 'SomeText'

它给出以下错误:

An error occurred (BadRequestException) when calling the UpdateIntegration operation: Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: SomeText]

amazon-web-services aws-api-gateway aws-cloudshell
1个回答
0
投票

搜索后,我从https://repost.aws/knowledge-center/api-gateway-vpc-link-integration

找到了答案
  1. 要检索集成 ID,请运行类似于以下内容的 AWS CLI 命令 get-integrations:

aws apigatewayv2 get-integrations --api-id <api-id>

  1. 按以下格式创建并保存名为 Integration.json 的 JSON 文件:
{
    "ApiId": "<api-id>",
    "IntegrationId": "<integration id retrieved from previous step>",
    "RequestParameters": {
        "integration.request.header.ConnectionId": "context.connectionId", //passing context variable connectionId as ConnectionId header to backend
        "integration.request.header.any-header-key": "''static value'",   //passing static value as querystring to backend
        "integration.request.querystring.any-querystring-key": "'static value'"
    } 
} ```
  1. 要更新集成,请运行类似于以下内容的 AWS CLI 命令 update-integration:

aws apigatewayv2 update-integration --cli-input-json file://integration.json

  1. 部署您的 API
© www.soinside.com 2019 - 2024. All rights reserved.