amazon-web-services - 在 API Gateway 中设置查询字符串和 header 的名称

标签 amazon-web-services aws-api-gateway aws-cloudformation

这是我如何设置堆栈的示例。我只发布了其中的一部分,请放心,堆栈工作正常。

问题我想问一下,如何在 url 级别指定特定的 queryString 名称。现在在 AWS 控制台(Web UI)上,它显示 {orderId} 但我希望它显示其他内容。我该如何修改它?

此外,它还会在 AWS UI 上显示 HEADERS 框的 {orderId}。我也想改变这一点。

OrdersPathResource:
    Type: "AWS::ApiGateway::Resource"
    Properties:
        RestApiId:
            Ref: "XYZApi"
        ParentId: !GetAtt [XYZApi, RootResourceId]
        PathPart: "orders"

OrdersIdPathResource:
    Type: AWS::ApiGateway::Resource
    Properties:
        RestApiId:
            Ref: "XYZApi"
        ParentId:
            Ref: "OrdersPathResource"
        PathPart: "{ordersId}"

StatusPathResource:
    Type: AWS::ApiGateway::Resource
    Properties:
        RestApiId:
            Ref: "XYZApi"
        ParentId:
            Ref: "OrdersIdPathResource"
        PathPart: "status"

GetOrdersShipmentStatusMethod:
    Type: "AWS::ApiGateway::Method"
    Properties:
        ApiKeyRequired: true
        AuthorizationType: "AWS_IAM"
        HttpMethod: "GET"
        ResourceId:
            Ref: "StatusPathResource"
        RestApiId:
            Ref: "XYZApi"
        Integration:
            Type: "AWS_PROXY"
            IntegrationHttpMethod: "POST"
            Uri: !Join ["", ["arn:aws:apigateway:", !Ref "AWS::Region", ":lambda:path/2015-03-31/functions/",!GetAtt GetOrdersShipmentStatusLambdaFunction.Arn, "/invocations"]]

最佳答案

从您的 CloudFormation 模板片段中,您正在使用 Lambda 代理集成,因此 API Gateway 不允许您设置到集成的参数映射。但是如果你想在方法端有请求参数,你可以将你的方法更改为类似的内容,

    GetOrdersShipmentStatusMethod:
    Type: "AWS::ApiGateway::Method"
    Properties:
        ApiKeyRequired: true
        AuthorizationType: "AWS_IAM"
        HttpMethod: "GET"
        ResourceId:
            Ref: "StatusPathResource"
        RestApiId:
            Ref: "XYZApi"
        RequestParameters:
            method.request.header.headerName: false
            method.request.querystring.querystringName: false
        Integration:
            Type: "AWS_PROXY"
            IntegrationHttpMethod: "POST"
            Uri: !Join ["", ["arn:aws:apigateway:", !Ref "AWS::Region", ":lambda:path/2015-03-31/functions/",!GetAtt GetOrdersShipmentStatusLambdaFunction.Arn, "/invocations"]]

关于amazon-web-services - 在 API Gateway 中设置查询字符串和 header 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45176617/

相关文章:

amazon-web-services - 从 lambda 记录到 cloudwatch 中的特定日志流

aws-cloudformation - AWS 云形成 : Template format error: At least one Resources member must be defined

amazon-web-services - 默认VPC中不存在该安全组

amazon-web-services - 如何在 aws cloudformation 模板中限制特定于 SQS 的 IAM 角色

amazon-web-services - AWS : How to programmatically create a RDS Aurora Cluster in Python/Boto3

angular - Docker 或适用于 AWS 的 Docker 以及在 AWS EC2 上的部署

amazon-web-services - S3 存储桶文件夹的 DNS 名称

amazon-web-services - Api Gateway Stages 的不同 Cognito 池授权器

csv - API 网关 + Lambda 下载 CSV 文件

amazon-web-services - 使用 Firebase 的 AWS ApiGateway 自定义授权