0

I'm setting up a aws-apigateway-lambda and i'm new in that services.

I'm Wondering that how to use lambda getting individual methods(POST,GET...)?

For instances,

  1. Create Individual lambda function per http method.

GET api.com -> lambda.api.get

POST api.com -> lambda.api.post

  1. one lambda function and Accept all method
  1. GET,POST,DELETE... api.com -> lambda.api
def lambda_function(event,context):
    method = event["http-method"]
    if method == 'GET': return receive_get()
    elif method == 'POST': return receive_post()

which is efficient way ??

pakachu
  • 77
  • 1
  • 1
  • 13

1 Answers1

1

If you consider an equally traffic two lambda functions with around same number of containers warmed, both lambda will take around equal amount of time to process. So, it actually depends on the traffic pattern of your lambda service. Say for example we consider both cases:

  1. If your service does not have regular traffic, you will have to spin up containers to keep your lambda warm. But in this case if you have different lambdas then you will be burdened with warming two lambda functions.

  2. Your service has regular traffic, then there are not much cold start issues in lambda and being single or two lambda won't have much difference in processing unless including both methods makes your code too extensive and heavy making spinning of lambda containers more time consuming. But in normal get and post method cases it is not the case.

So, basically you have to decide whether including both get and post methods in the same lambda makes your code heavy. If it does it this can increase the time for spinning up new lambda containers. As you are using python it adds very less to cold start time and it will be better to put both methods in the same lambda.

For lambda cold start related issues you can look at these: