getting message: forbidden reply from AWS API gateway

前端 未结 20 1071
鱼传尺愫
鱼传尺愫 2020-11-30 04:34

I am trying to create a lambda service on AWS and have it accessed from outside via the API gateway with no authentication or restriction required.

To make things ea

相关标签:
20条回答
  • 2020-11-30 05:02

    If you set 'API Key Required' option to true, please check below.

    1. you have to pass 'x-api-key' HTTP Header Parameter to API Gateway.
    2. The API Key had to be created.
    3. In addition, you need to check a Usage Plan for the API Key on API Gateway Console.
    0 讨论(0)
  • 2020-11-30 05:03

    I might have come across a solution to this problem. I had the same issue right now on MacOS. I tried to flush my DNS and then it worked!

    Try this in the terminal:

    Mac OS X Yosemite and later

    sudo killall -HUP mDNSResponder
    

    Mac OS X Yosemite v10.10 through v10.10.3

    sudo discoveryutil mdnsflushcache
    

    Mac OS X Mavericks, Mountain Lion and Lion

    sudo killall -HUP mDNSResponder
    

    Mac OS X Snow Leopard

    sudo dscacheutil -flushcache
    
    0 讨论(0)
  • 2020-11-30 05:03

    As @gary69 and @Adriaan Pelzer mentions

    https://stackoverflow.com/a/52727654/809043

    https://stackoverflow.com/a/55136675/809043

    You can get the message {"message":"Forbidden"} when requesting a Private API.

    So if you have a setup where all traffic should go thorough a API Endpoint which than directs the traffic to the API Gateway then the following parameters may be used.

    APIGatewayVPCEndpoint:
      Type: 'AWS::EC2::VPCEndpoint'
      Properties:
        PolicyDocument: '{
            "Version":"2012-10-17",
            "Statement":[{
              "Effect":"Allow",
              "Principal": "*",
              "Action":["execute-api:Invoke"],
              "Resource":["arn:aws:execute-api:eu-north-1:000000000000:*/*"]
            }]
          }'
      ...
      VpcEndpointType: Interface
      PrivateDnsEnabled: true
    

    If PrivateDnsEnabled is enabled, than the endpoint in the API Gateway needs to be of Type Private, and a policy needs to added.

      ApiGatewayRest:
        Type: AWS::ApiGateway::RestApi
        Properties:
          Description: A mocked API
          Name: Mocked API
          EndpointConfiguration:
            Types:
              - PRIVATE
          Policy: '{
            "Version": "2012-10-17",
            "Statement": [{
              "Effect": "Allow",
              "Principal": "*",
              "Action": "execute-api:Invoke",
              "Resource": "arn:aws:execute-api:eu-north-1:000000000000:*/*/*/*"
            }]
          }'
    

    This forum thread helped clear out some of the details for me

    https://forums.aws.amazon.com/thread.jspa?threadID=286760

    0 讨论(0)
  • 2020-11-30 05:06

    I had a similar problem, and I had the following:

    1. A Custom Domain (Edge Optimized)
    2. Multiple Stages (dev, staging, prod)

    I also didn't set any Authorization nor restrictions to make things simple.

    I was able to fix the problem by adding Base Path Mappings for each of my stages (dev, staging, prod).

    0 讨论(0)
  • 2020-11-30 05:06

    I got {"message":"Forbidden"} on an API with EndpointConfiguration set to PRIVATE, and a VpcEndpoint created for it in the Vpc's private subnets (this is an inter-service API)

    The reason I got {"message":"Forbidden"} was that I was under the impression I should use one of the VpcEndpoint's urls. The URL to use is still the one associated with the stage (in ApiGateway console). It is:

    https://${RestApiId}.execute-api.${Region}.amazonaws.com/${StageName}

    0 讨论(0)
  • 2020-11-30 05:07

    I got this error from an nginx fargate service trying to access a private API in API Gateway. I needed to add a policy under resource policies in my api like this

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Principal": "*",
                "Action": "execute-api:Invoke",
                "Resource": "arn:aws:execute-api:us-east-1:<AccountID>:<RestApiID>/*",
                "Condition": {
                    "StringEquals": {
                        "aws:sourceVpce": "<VPC Endpoint ID for execute-api>"
                    }
                }
            }
        ]
    }
    
    0 讨论(0)
提交回复
热议问题