Trying to deploy a simple HelloWorld API using CloudFormation/SAM.
I have to defined an AWS::Serverless::Api, AWS::ApiGateway::Resource, AWS::ApiGateway::Method and a AWS::ApiGateway::Deployment. But during sam deploy I see that another AWS::ApiGateway::Deployment is implicitly created, one that is deployed before the API Method.
The API related resources deployed:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Operation LogicalResourceId ResourceType Replacement
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Add HelloWorldAPIDeployment5332c373d4 AWS::ApiGateway::Deployment N/A
+ Add HelloWorldAPIDeployment AWS::ApiGateway::Deployment N/A
+ Add HelloWorldAPIMethod AWS::ApiGateway::Method N/A
+ Add HelloWorldAPIResource AWS::ApiGateway::Resource N/A
+ Add HelloWorldAPIStage AWS::ApiGateway::Stage N/A
+ Add HelloWorldAPI AWS::ApiGateway::RestApi N/A
How can I stop the implicit AWS::ApiGateway::Deployment(HelloWorldAPIDeployment5332c373d4) from being created?
It causes the following error:
CREATE_FAILED AWS::ApiGateway::Deployment HelloWorldAPIDeployment5332c373d4 Resource handler returned message: "The REST
API doesn't contain any methods (Service:
ApiGateway, Status Code: 400, Request ID:
02f3dcab-0126-4d16-8c19-27fb1e05c381,
Extended Request ID: null)" (RequestToken:
d75d527f-da4f-78a5-3000-be3e156ccc7a,
HandlerErrorCode: InvalidRequest)
Here's the relevant template code:
HelloWorldAPI:
Type: AWS::Serverless::Api
Properties:
Name: HelloWorldApi
StageName: !Ref StageName
HelloWorldAPIResource:
Type: AWS::ApiGateway::Resource
Properties:
RestApiId: !Ref HelloWorldAPI
ParentId: !GetAtt HelloWorldAPI.RootResourceId
PathPart: hello
HelloWorldAPIMethod:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
ResourceId: !Ref HelloWorldAPIResource
RestApiId: !Ref HelloWorldAPI
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: POST
Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloWorldFunction.Arn}/invocations
# - Arn: !GetAtt HelloWorldFunction.Arn
HelloWorldAPIDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId: !Ref HelloWorldAPI
StageName: !Ref StageName
DependsOn:
- HelloWorldAPIMethod