Search code examples
aws-api-gatewayserverless

AWS Private API gateway deployment error when using serverless deploy


I am hitting the below error when I try to create a PRIVATE endpoint type using serverless in AWS.

Below is the serverless.yml file for reference

provider:
  name: aws
  endpointType: PRIVATE
  vpcEndpointIds:
    - vpce-xxxx
  region: ap-southeast-2
  apiKeys:
    - ${self:custom.actualStage}-xxxxxx2
  resourcePolicy:
    - Effect: Allow
      Principal: '*'
      Action: execute-api:Invoke
      Resource:
        - execute-api:/*/*/*
      Condition:
        StringEquals:
          aws:SourceVpc:
            - "vpc-xxxxx"
  plugins:
    - serverless-plugin-warmup

  iamRoleStatements:
    - Effect: 'Allow'
      Action:
        - 'lambda:InvokeFunction'
      Resource: "*"

Error from logs:

CREATE_FAILED: ApiGatewayDeployment1655171823778 (AWS::ApiGateway::Deployment) Resource handler returned message: "Private REST API doesn't have a resource policy attached to it (Service: ApiGateway, Status Code: 400, Request ID: e321f00e-42b6-4ef6-b984-46500ca40492)" (RequestToken: 475924b8-998d-58fc-89bd-51fc0b80f2d4, HandlerErrorCode: InvalidRequest)


Solution

  • Not sure if AWS released new changes in the serverless configuration for API GW. Your policy version should have worked. However, I have tested this on my end. We now have to mention the resourcePolicy under the apiGateway attribute. Please use the following this will resolve your issue:

    apiGateway:
      resourcePolicy:
        - Effect: Allow
          Principal: '*'
          Action: execute-api:Invoke
          Resource:
            - execute-api:/*
        - Effect: Deny
          Principal: '*'
          Action: execute-api:Invoke
          Resource:
            - execute-api:/*
          Condition:
            StringNotEquals:
              aws:SourceVpc:
                - 'vpc-*******'