路径之前的API网关cloudformation方法

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

我正在为api网关编写cloudformation,在资源路径和方法上遇到此排序问题。

path ordering issue

我想要的是使路径(/ hi)在其上一层,而方法GET在其下。

这是我编写的用于生成此消息的cloudformation脚本的摘要(排除的权限,lambda,策略等...),我也知道一些用于执行此操作的工具,但我们不认可这些工具情况。

MyAPI:
    Type: AWS::ApiGateway::RestApi
    Properties: 
      Name: "TestAPI"
      EndpointConfiguration:
        Types: 
          - REGIONAL

ApiGatewayResourceHi:
    Type: "AWS::ApiGateway::Resource"
    Properties: 
      ParentId:
        Fn::GetAtt: ["MyAPI", "RootResourceId"]
      PathPart: "hi"
      RestApiId:
        Ref: "MyAPI"

HiMethodGet:
    Type: "AWS::ApiGateway::Method"
    Properties:
      RestApiId: !Ref MyAPI
      ResourceId: !GetAtt
        - MyAPI
        - RootResourceId
      HttpMethod: GET
      AuthorizationType: NONE
      Integration: 
        IntegrationHttpMethod: "POST"
        Type: "AWS_PROXY"
        Uri: !Join ["", ["arn:", !Ref "AWS::Partition", ":apigateway:", !Ref "AWS::Region", ":lambda:path/2015-03-31/functions/", !GetAtt ["HiLambdaFunction", "Arn"], "/invocations"]]
    DependsOn:
      - ApiGatewayResourceHi

ApiGatewayDeployment1: 
    Type: "AWS::ApiGateway::Deployment"
    Properties: 
      RestApiId: 
        Ref: "MyAPI"
      StageName: "dev"
    DependsOn:
      - HiMethodGet

一切似乎都正常,我可以调用并命中端点,它的响应也很好。这只是这个排序问题,因为我们其他一些api网关的结构是在方法之前使用路径的(尽管它们是手动创建的)。也许这是正确的方法,这很好吗?如果有人在我的脚本或这两种布局之间的建议中发现问题,我将不胜感激。

谢谢。

amazon-web-services amazon-cloudformation
2个回答
1
投票

您正在以图形方式描述希望API在控制台中显示的样子,因为“ GET”位于“ / hi”下方。控制台显示的是“ GET”方法已附加到根路径,并且根路径具有名为“ hi”的资源,该资源没有方法。我假设您希望“ hi”资源具有GET方法,该方法将按照您的描述显示,并且看起来像是一个逻辑api设计。

之所以创建它,是因为将方法的资源设置为RootResourceId:

      ResourceId: !GetAtt
        - MyAPI
        - RootResourceId

您要做的是将资源设置为“ Hi”方法:

      ResourceId: !GetAtt
        - MyAPI
        - HiMethodGet

0
投票

我以我想要的方式运行它,@@ Classic建议它不起作用,但它可以帮助查明问题,这是我必须对其进行更改才能使其正常工作。

ApiGatewayResourceHi:
    Type: "AWS::ApiGateway::Resource"
    Properties: 
      ParentId:
        Fn::GetAtt: ["MyAPI", "RootResourceId"]
      PathPart: "hi"
      RestApiId:
        Ref: "MyAPI"

HiMethodGet:
    Type: "AWS::ApiGateway::Method"
    Properties:
      RestApiId: !Ref MyAPI
      ResourceId: !Ref ApiGatewayResourceHi

......
© www.soinside.com 2019 - 2024. All rights reserved.