I am using SAM to deploy a simple Hello world application. One with one API Endpoint, which will trigger a lambda function that returns the text hello world. I have defined the following resources:
- IAM Role so that APIGateway can invoke lambda functions.
- AWS::ApiGateway::RestApi
- AWS::ApiGateway::Resource
- AWS::ApiGateway::Method
- AWS::Serverless::Function
Admittedly, I do not know the difference in functionality between 2. and 3. yet.
During sam deploy
I see the following error.
ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack go-hello-world The following resource(s) failed to create:
[HelloWorldAPIResource,
HelloWorldFunctionRole]. Rollback requested by
user.
CREATE_FAILED AWS::IAM::Role HelloWorldFunctionRole Resource creation cancelled
CREATE_FAILED AWS::ApiGateway::Resource HelloWorldAPIResource Resource handler returned message: "Invalid
Resource identifier specified (Service:
ApiGateway, Status Code: 404, Request ID:
62f34d79-86ab-47fd-85b1-5fbb55071520, Extended
Request ID: null)" (RequestToken:
9633d7db-7b6d-881b-f54e-ca0114862fd8,
HandlerErrorCode: NotFound)
Which means that the AWS::ApiGateway::Resource is not getting a valid reference to AWS::ApiGateway::RestApi.
Here is the relevant part from my template.yml
HelloWorldAPI:
Type: AWS::ApiGateway::RestApi
Properties:
Name: HelloWorldApi
HelloWorldAPIResource:
Type: AWS::ApiGateway::Resource
Properties:
RestApiId: !Ref HelloWorldAPI
ParentId: "/"
PathPart: hello
I am new to both CloudFormation and AWS in general, any help is appreciated.
CodePudding user response:
It should be:
ParentId: !GetAtt HelloWorldAPI.RootResourceId