0
votes

The scenario is :

  1. I have a Rest api gateway which when triggered invokes a lambda which processes the request and returns the repsonse.
  2. This api endpoint is public.
  3. I have another lambda which will call this API gateway/endpoint and obtain response from it.

Now the queries :

  1. I am directly calling the invoke url of api just like any other api. So is this the right way to do so?
  2. When I put the invoke url in browser address bar, it is giving missing authentication token.
  3. How to actually call the url in calling lambda, i mean how to pass tokens; in Node.js ?

Thanks ????

1

1 Answers

1
votes

Well, the questions are quite wide enough. I'm trying to answer as much as possible.

First, the design you are following of Rest API -> Lambda, it is called 'Integration Type' is 'Lambda function' and use 'Use Lambda Proxy integration'.

Please take a look on the documentation here and an example here

Go through the document I believe you will understand in-out of this model. At high level, this model API Gateway is passing through request and response and you (Lambda) will handle everything.

enter image description here enter image description here

Question 1: I am directly calling the invoke url of api just like any other api. So is this the right way to do so?

[Answer] There is nothing wrong with this model. And yes, you can call this API (Lambda proxy) as any Rest API.

Question 2: When I put the invoke url in browser address bar, it is giving missing authentication token

[Answer] Please check the setting of your API. As the below screen-shot, my api is using Cognito as Authorizer. It means consumers need to provide 'Token' (oAuth2 for example) when calling the API. You can use either Lambda authorizer or Cognito authroizer. It's up to you. And if you are not requiring any authorizer, you can set it as NONE so there is no authentication token require for your API.

In short, the message you are getting now it means your API is having an 'Authorizer' and you are not sending token along with request.

enter image description here

Question 3: How to actually call the url in calling lambda, i mean how to pass tokens; in Node.js ?

It is pretty common. You can google it like 'oAuth2 in Node.js', it will give you tons of examples

https://resources.infosecinstitute.com/securing-web-apis-part-ii-creating-an-api-authenticated-with-oauth-2-in-node-js/

https://stormpath.com/blog/talking-to-oauth2-services-with-nodejs

I hope it helps. Otherwise, leave your comments and questions.

Thanks,