8

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
  • So you basicly calll rest api endpoint just like in any programming language you are using, outside of clouds and all of it ? Why I didnt think about it... instead I was thinking that there has to be some special aws way of doing it...
    – 10101101
    Commented Aug 25, 2023 at 8:22

1 Answer 1

5

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,

2
  • Comment 2. Regarding answer of question 1, the current stage is test and i can see invoke url for this stage. when the prod stage will be added, will the invoke url change, how to let the program automatically decide which url to call depending on process.env.ENV
    – Yusuf
    Commented Jul 25, 2020 at 16:06
  • Comment 3. Regarding answer of question 2, the Authorizer tab in api gateway is empty and there is one create authorizer button. However in api key source, header is selected instead of authorizer
    – Yusuf
    Commented Jul 25, 2020 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.