在APIGateway中设置查询字符串和标题的名称

时间:2017-07-18 20:38:06

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

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

问题我想问一下,我如何在网址级别具体queryString名称。现在在AWS控制台(Web UI)上,它显示{orderId},但我希望它显示其他内容。我该怎么修改呢?

此外,它还会在AWS用户界面上为{orderId}框显示HEADERS。我也希望改变它。

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"]]

1 个答案:

答案 0 :(得分:0)

在您的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"]]