1
votes

How to specify ParentId of existing "AWS::ApiGateway::RestApi" for "AWS::ApiGateway::Resource" in CloudFormation template? For example, I have already created API Gateway REST API and I want to specify it in my template:

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

In case when I describe "AWS::ApiGateway::RestApi" in my template too I can do that such way:

  ParentId: !GetAtt "RestApi.RootResourceId"

But how can I do that for already existing REST API?

2
Is your already existing REST API in the same CloudFormation stack as MyTestResource ? - spg
Yes. In short, I need to add a new resourse to existing REST API using CloudFormation template - Gleb

2 Answers

1
votes

You can lookup the resource id of an existing REST API either through the console Click "your REST API" -> "Resources" in the higher left side you'll see something like

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

That's then the resource Id you can specify as a "parentId". Alternatively, use the aws cli.

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

Where you'd need to specify the rest-api-id which you again can either get from the console, or via https://docs.aws.amazon.com/cli/latest/reference/apigateway/get-rest-apis.html

1
votes

In fact, if you need to specify a new resource in an existing API, you can check the stack in the CloudFormation, in the resources tab and see the Logical Did with which the API was generated.

Whit that LogicalId you can specify en that manner, considering logical Id as RestApiLogicalId:

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

Enjoy!