Ismael Treviño
Ismael Treviño

Reputation: 21

Serverless Framework - AWS Lambda Functions

I have one deployed in AWS with the help of the serverless framework, several lambda functions. The functions work correctly. But they take time to run, since they have to unzip a zip file with the python requirements. When I run the function for the first time, the function does not have time to decompress and execute in less than 30 seconds (30 seconds in the API Gateway limitation). So it returns HTTP error 503 service unavailable I understand Serverles Framwork, it also creates a cache policy using, that's why when I call it again for the second time, the function executes correctly. When a few minutes go by without me calling it, the cache is cleared, and it fails again the first time I call it.

What could I do to eliminate this unwanted behavior? Do I have to put any extra configuration for serverless framework? Do I have to configure something in AWS?

Upvotes: 0

Views: 83

Answers (1)

chyke007
chyke007

Reputation: 1463

You can make use of AWS Lambda Provisioned Concurrency. This helps keep the function warm till it's called again.

Read more about it here

Since you are using the Serverless framework, you can do it like this:

functions:
  hello:
    handler: handler.hello
      events:
        - http:
            path: /hello
          method: get
    provisionedConcurrency: 5

Upvotes: 0

Related Questions