Functions Timeout and Memory - amresh087/newronaRepos GitHub Wiki

Functions Timeout and Memory

let create python project you can create any project after that we need to add config in serverless.yml file

Now we need add some property in serverless.yml

  service: my-aws-python3-demo
  frameworkVersion: '3'

  provider:
    name: aws
    runtime: python3.9

  functions:
    hello-short-timeout:
      handler: handler.hello
      timeout: 3
      memorySize: 128
    hello-long-timeout:
      handler: handler.hello
      timeout: 6
      memorySize: 256    

Here we have defind there are two function called hello-short-timeout and hello-long-timeout but both are using same handler called handler.hello

  import json
  import time  
  def hello(event, context):
      print("hello world")
      time.sleep(4)
      return "another hello world"

Here we have added sleep method for 4ms but I have set timeout in first method 3ms and second method 6ms. Hence first method will throw timeout error and second function will give response

Inheriting Settings from the Provider Property

if you want inherit property then defined in Provider level

  service: my-aws-python3-demo
  frameworkVersion: '3'

  provider:
    name: aws
    runtime: python3.9
    timeout: 2
    memorySize: 512

  functions:
    hello-short-timeout:
      handler: handler.hello
      timeout: 3
      memorySize: 128
    hello-long-timeout:
      handler: handler.hello
      timeout: 6
      memorySize: 256