Skip to main content

Lambda update function timeout

Lambda update function timeout causes a timeout of a Lambda function, thereby updating the timeout to a specific value for a certain duration. Timeout errors interrupt the flow of the given function. Hitting a timeout is a frequent scenario with Lambda functions. This can break the service and impact the delivery. Such scenarios can occur despite the availability aids provided by AWS.

Lambda Update Function Timeout

Use cases

Lambda update function timeout:

  • Checks the performance of the application (or service) running with a new timeout.
  • Determines a safe overall timeout value for the function.

Prerequisites

  • Kubernetes >= 1.17
  • Access to operate AWS Lambda service.
  • Lambda function must be up and running.
  • Kubernetes secret must have the AWS access configuration(key) in the CHAOS_NAMESPACE. A secret file looks like this:
    apiVersion: v1
    kind: Secret
    metadata:
    name: cloud-secret
    type: Opaque
    stringData:
    cloud_config.yml: |-
    # Add the cloud AWS credentials respectively
    [default]
    aws_access_key_id = XXXXXXXXXXXXXXXXXXX
    aws_secret_access_key = XXXXXXXXXXXXXXX
tip

HCE recommends that you use the same secret name, that is, cloud-secret. Otherwise, you will need to update the AWS_SHARED_CREDENTIALS_FILE environment variable in the fault template with the new secret name and you won't be able to use the default health check probes.

Below is an example AWS policy to execute the fault.

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:UpdateFunctionConfiguration",
"lambda:GetFunctionConcurrency",
"lambda:GetFunction",
"lambda:DeleteFunctionConcurrency",
"lambda:PutFunctionConcurrency"
],
"Resource": "*"
}
]
}
note

Mandatory tunables

Tunable Description Notes
FUNCTION_NAME Function name of the target Lambda function. It support single function name. For example, test-function
FUNCTION_TIMEOUT Value of function timeout in seconds. Minimum value: 1 s and maximum: 900 s (15 minutes). For more information, go to timeout value.
REGION The region name of the target lambda function For example, us-east-2

Optional tunables

Tunable Description Notes
TOTAL_CHAOS_DURATION Duration that you specify, through which chaos is injected into the target resource (in seconds). Default: 30 s. For more information, go to duration of the chaos.
AWS_SHARED_CREDENTIALS_FILE Path to the AWS secret credentials. Default: /tmp/cloud_config.yml.
CHAOS_INTERVAL The interval (in seconds) between successive instance termination. Default: 30 s. For more information, go to chaos interval.
SEQUENCE It defines sequence of chaos execution for multiple instance Default: parallel. Supports serial and parallel. For more information, go to sequence of chaos execution.
RAMP_TIME Period to wait before and after injection of chaos in seconds For example, 30 s. For more information, go to ramp time.

Timeout value

Updates the Lambda function timeout value to a different value. Tune it by using FUNCTION_TIMEOUT environment variable.

The following YAML snippet illustrates the use of this environment variable:

# contains the timeout value for the lambda function
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: lambda-update-function-timeout
spec:
components:
env:
# provide the function timeout for 10seconds
- name: FUNCTION_TIMEOUT
value: '10'
# provide the function name for timeout chaos
- name: FUNCTION_NAME
value: 'chaos-function'