代码之家  ›  专栏  ›  技术社区  ›  Hleb

在cloudformation模板中为“aws::apigateway::resource”指定parentid

  •  1
  • Hleb  · 技术社区  · 8 年前

    如何在cloudformation模板中为“aws::apigateway::resource”指定现有“aws::apigateway::restapi”的parentid?例如,我已经创建了api gateway rest api,我想在我的模板中指定它:

     MyTestResource:
        Type: 'AWS::ApiGateway::Resource'
        Properties:
          RestApiId:
            Ref: 'RestApi'
          ParentId: <<placeholder_for_my_value>>
    

    如果我也在模板中描述“aws::apigateway::restapi”,我可以这样做:

      ParentId: !GetAtt "RestApi.RootResourceId"
    

    但是,对于已经存在的rest api,我如何才能做到这一点呢?

    2 回复  |  直到 8 年前
        1
  •  1
  •   Nune Isabekyan    8 年前

    您可以通过控制台查找现有rest api的资源id 单击“您的rest api”->“资源” 在左上方你会看到

     APIs>YOUR_API_NAME (YOUT_API_ID)>Resources>/your_already_existing_resource (YOUR_RESOURCE_ID)
    

    这就是您可以指定为“parentid”的资源id。 或者,使用 aws CLI。

    https://docs.aws.amazon.com/cli/latest/reference/apigateway/get-resources.html

    您需要指定 rest-api-id 你也可以从控制台或者通过 https://docs.aws.amazon.com/cli/latest/reference/apigateway/get-rest-apis.html

        2
  •  1
  •   Yunier Saborit Ramírez    7 年前

    实际上,如果需要在现有api中指定新资源,可以在resources选项卡的cloudformation中检查堆栈,并查看生成api的逻辑did。

    使用该逻辑ID,您可以以这种方式指定,将逻辑ID视为 餐馆 :

     "ParentId": {
              "Fn::GetAtt": [
                "RestApiLogicalId",
                "RootResourceId"
              ]
            }
    

    享受!