3

I need to fetch some data from ApiGateway endpoint and then based on response store this data in database.

I created simple Lambda function that just fetch data from ApiGateway endpoint and print it in console. My first Lambda function did not have any VPC configuration and fetch operation worked like a charm.

const fetch = require('node-fetch');

exports.handler = async () => {
  const data = await fetch("https://<<ag-api-key>>.execute-api.us-east-1.amazonaws.com/v1/data");
  const response = await data.json();
  console.log(data, response);
}

As I need to store data received from endpoint into database which run under VPC I decided to put Lambda in same VPC(this vpc has configured Internet Gateways and other stuff to have access to internet). As a result fetch operation start to fail with 403 response code and {"message":"Forbidden"} response body.

Api Gateway resource does not have any custom domain configuration and maintained by other team so I do not have direct access to its configuration

May be anyone can suggest how I can fix this

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Aliaksei Bulhak
  • 6,078
  • 8
  • 45
  • 75

1 Answers1

1
  1. Security Groups, check if port 443 is open
  2. Check your CORS Setting on API Gateway.
  3. Try Hitting the API Gateway with Postman/Fiddler, or any other testing tool to make sure your API Gateway is online and you can get the response you want.
  4. If you are using a Private API-Gateway (Sounds like you are using public looking at the URL) you will need some header data and different URL. I can guide you through it if needed. I would avoid private API gateway if I were you.

Let me know if any of that helps. I have ran into that issue many times in different situations.

Yuri
  • 4,254
  • 1
  • 29
  • 46
Mikes3ds
  • 592
  • 5
  • 12
  • 1
    I'm having the same issue but my VPC has no internet access. When I create an endpoint to it, I get a Forbidden response If private DNS is flagged. If I don't flag it, I get a timeout response. I wonder what did you guys make to sort it out. Thanks – Matheus Maximo Jul 17 '19 at 12:47
  • @MatheusMaximo hi Matheus, I am facing with the same issue, I wonder how did you fix your issue? – Halil İbrahim Özdoğan Aug 17 '20 at 10:57
  • 1
    @HalilİbrahimÖzdoğan there's a long list of settings to follow and set up the Lambda for that. You can find it here: https://blog.theodo.com/2020/01/internet-access-to-lambda-in-vpc/ – Matheus Maximo Aug 18 '20 at 09:26