Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

359
Views
One Lambda Function OR Multiple Lambda Functions

Can I write one Lambda Function to Handle Multiple REST API Requests. I have my data in Dynamo DB

Flow: API Gateway-->Lambda Function-->Dynamo DB Example:

Request1:GET Method-Need to pull data from Table1
/device/{device_id}/start/{start_date}/end/{end_date}/events


Request2:GET Method-Need to pull data from Table2
/device/{device_id}/start/{start_date}/end/{end_date}/event_count

Request3:POST Method-Need to put data from Table3
/device/{device_id}/start/{start_date}/end/{end_date}/fault_events

What is the best solution should I write 3 different lambda functions to handle 3 different requests or can I handle all the 3 requests in one BIG Lambda Function.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Yes, you can have one Lambda function that handle more than one API. The question is why?

Doing this is considered (almost) an anti-pattern as you won't be able to scale independently the various scenario.

These are two slides from the link pasted above from Chris Munns talk at last re:invent and I strongly agree.

enter image description here enter image description here

over 4 years ago · Santiago Trujillo Report

0

While I don't know enough about your use case to recommend using 1 or multiple Lambda, I can explain one way of working with all queries inside one function.

You can pass in parameters from the lambda event, which come from the AWS API parameters and then use these to determine following logic. An example would look like this -

def lambda_handler(event, context):
    try:
        type_query = str(event['queryStringParameters']['type_query'])
        if type_query == 'x':
            ...do the things
        elif type_query == 'y':
            ...do the other things
        elif type_query == 'z':
            ...do the 3rd thing
    except:
        return {
            'body': "Invalid Params"
        }

Hope this helps!

over 4 years ago · Santiago Trujillo Report

0

You have to find the right balance based on what your application/service does. In general I like to break things down into pretty small pieces, but you need to be careful you aren't going too far, and creating nano-services, which many consider an anti-pattern due to the maintenance overhead you end up creating.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!