Skip to main content

Lambda update function memory

Lambda update function memory causes the memory of a Lambda function to be updated to a specified value for a certain duration.

  • It checks the performance of the application (or service) running with a new memory limit.
  • It helps determine a safe overall memory limit value for the function.
  • Smaller the memory limit higher will be the time taken by the Lambda function under load.

Lambda Update Function Memory

Usage

View fault usage
Hitting a memory limit with Lambda functions may slow down the service and impact their delivery. Running out of memory due to smaller limits may interrupt the flow of the given function. These fault helps build resilience to such unexpected scenarios.

Prerequisites

  • Kubernetes >= 1.17
  • Access for operating AWS Lambda functions.
  • Kubernetes secret that has 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
  • It is recommended to use the same secret name, i.e. cloud-secret. Otherwise, you will need to update the AWS_SHARED_CREDENTIALS_FILE environment variable in the fault template and you may be unable to use the default health check probes.

  • Refer to AWS Named Profile For Chaos to know how to use a different profile for AWS faults.

Permissions required

Here is an example AWS policy to execute the fault.

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

Refer to the superset permission/policy to execute all AWS faults.

Default validations

The Lambda function should be up and running.

Fault tunables

Fault tunables

Mandatory fields

Variables Description Notes
FUNCTION_NAME Function name of the target lambda function. It supports single function name. For example, test-function
MEMORY_IN_MEGABYTES Provide the value of the memory limit of a function in megabytes. The minimum value of the memory limit on a lambda function is 128Mb and the maximum upto 10240Mb
REGION The region name of the target lambda function For example, us-east-2

Optional fields

Variables Description Notes
TOTAL_CHAOS_DURATION The total time duration for chaos insertion in seconds Defaults to 30s
CHAOS_INTERVAL The interval (in seconds) between successive instance termination. Defaults to 30s
SEQUENCE It defines sequence of chaos execution for multiple instance Default value: parallel. Supported: serial, parallel
RAMP_TIME Period to wait before and after injection of chaos in seconds For example, 30

Fault examples

Common and AWS-specific tunables

Refer to the common attributes and AWS-specific tunables to tune the common tunables for all faults and aws specific tunables.

Memory limit

It can update the Lambda function memory limit to a newer value by using MEMORY_IN_MEGABYTES environment variable as shown below.

Use the following example to tune it:

# contains the memory limit 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-memory
spec:
components:
env:
# provide the function memory limit
- name: MEMORY_IN_MEGABYTES
value: '10'
# provide the function name for memory limit chaos
- name: FUNCTION_NAME
value: 'chaos-function'