AWS API Gateway deployment failing in Gitlab CI-CD

Viewed 58

I'm trying to deploy an AWS SAM application using Gitlab CICD which was successful at first but failing after that. The failure is happening with API Gateway resource. The deployment would be successful if I delete the stack and deploy it again, but then on checking the API Gateway in console, there would be no Methods associated with it.

Mappings:
  StackEnv:
    dev-stack:
      envm: "dev"
    uat-stack:
      envm: "qa"

Resources: 
  MessageBodyAPI: #API 
    Type: AWS::Serverless::Api
    Properties:
      DefinitionBody: 
        swagger: 2.0
        info:
          title: TestApi
        basePath: /
        schemes:
          - https
        x-amazon-apigateway-policy:
          Version: '2012-10-17'
          Statement:
          - Effect: Deny
            Principal: "*"
            Action: execute-api:Invoke
            Resource: "*"
            Condition:
              StringNotEquals:
                aws:sourceVpce:
                - vpce-xxxxxx
          - Effect: Allow
            Principal: "*"
            Action: execute-api:Invoke
            Resource: "*"
      Description: description
      EndpointConfiguration: Private
      MethodSettings: 
      - HttpMethod: POST
        ResourcePath: /sap-inventory
      Name: myAPI
      StageName: !FindInMap [StackEnv, !Ref AWS::StackName, envm]

  POSTMethod: #Method for MessageBodyAPI
    Type: 'AWS::ApiGateway::Method'
    Properties:
      RestApiId: 
        Ref: MessageBodyAPI
      ResourceId: 
        Fn::GetAtt: [
        "MessageBodyAPI",
        "RootResourceId"
        ]
      HttpMethod: POST
      AuthorizationType: NONE
      Integration:
        Type: AWS_PROXY
        IntegrationHttpMethod: POST
        Uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:xxxxxx:function:myfunction/invocations


  MessageBodyAPIDeployment:  #Deployment corresponding to MessageBodyAPI
    DependsOn: POSTMethod
    Type: AWS::ApiGateway::Deployment
    Properties: 
      Description: description
      RestApiId: 
        Ref: MessageBodyAPI
      StageName: !FindInMap [StackEnv, !Ref AWS::StackName, envm]

The error I'm receiving:

Resource handler returned message: "The REST API doesn't contain any methods (Service: ApiGateway, Status Code: 400)

Any help?

0 Answers
Related