Creating the resource

After we create the API, we can now create our first resource, which will be a test resource, and remove it later. We can add these lines to the end of our resources in order to create the resource:

"TestResource": { 
      "Type": "AWS::ApiGateway::Resource", 
      "Properties": { 
        "PathPart": "test", 
        "RestApiId": { 
          "Ref": "RestApi" 
        }, 
        "ParentId": { 
          "Fn::GetAtt": [ 
            "RestApi", 
            "RootResourceId" 
          ] 
        } 
      } 
    } 

If we analyze this resource, we can see that the resource type is AWS::ApiGateway::Resource . In the properties part, we can see PathPart , and we set it as test. It will create a REST resource and will be invoked when https://base_url/test is requested. Here, we can use brackets to create a dynamic parameter. For example, {test} would match both https://base_url/1 and https://base_url/2, and we can use these parameters to pass to our Lambda function. The RestApiId property refers to the AWS::ApiGateway::RestApi resource we just created, and ParentId refers to the RootResourceId value of the RestApi resource.

This is a bit tricky. Normally, you create resources referring to their parent resources. For example, to create a resource such as /users/{id}/picture, you have to create the users, {id}, and picture resources separately, and for each resource, you have to refer to the previous one. But for the users resource, you do not have a parent resource. In that case, you should refer to the RootResourceId value of the REST API.