1

I have just started with AWS Serverless and I am having some doubts. Here is my use case and what I have tried and done so far:

Use Case:

Make multiple GET and POST requests to an API using HTTP API(not REST API) in AWS using lambda function.

What I have done:

Created an HTTP API. Using $default stage currently. Created a POST route. Created a function(in python) with POST request. Attached the function integration with my POST route. I am successfully able to call this route using my frontend code(written in vanilla js). Using the data that I receive from frontend, I call an external API using it's URL in my python lambda function.

Problem:

I want to make a GET request to another API using it's URL. Will I have to make another lambda function to do so?

Any help will be great. Pardon me if I have asked a silly question. It's just that I am new to AWS and HTTP API. Thank You for your time!

Shubh9718
  • 63
  • 12
  • 1
    A same lambda can be used for both GET and POST. – Marcin Feb 12 '21 at 06:15
  • @Marcin you mean the same lambda function with same python file? or will I need to create another file in the same lambda function? Also do I need to change my route from POST to ANY if I have to make both POST and GET request? – Shubh9718 Feb 12 '21 at 06:25
  • 1
    You can have two routes (GET, POST), or one ANY route. Same lambda file is fine. – Marcin Feb 12 '21 at 06:28
  • 1
    Thank you @Marcin. I will try it. You can add it as an answer so that I can accept it – Shubh9718 Feb 12 '21 at 06:30

1 Answers1

1

Based on the comments.

A single lambda function can be used for both POST and GET requests. For this, you can have either two routes, one for POST and one for GET. Both can be integrated with the same function.

Alternatively, you can have one ANY route to route everything into a single function.

The function can have same file and same handler. However, its logic must be probably modified to handle POST and GET events differently, depending on your use-case.

Marcin
  • 215,873
  • 14
  • 235
  • 294