Lambda update function memory
Lambda update function memory is an AWS fault that:
- Updates the memory of a Lambda function to a specific value during a chaos duration.
- Checks the performance of the application (or service) running with a new memory limit thereby determining a safe overall memory limit value for the function. The Lambda function takes longer to execute if the memory limit is reduced.
Fault execution flow chart
Usage
View fault usage
Hitting a memory limit is a common scenario with Lambda functions that slows down the service and impacts their delivery. Such scenarios occur despite the availability aids provided by AWS or determined by users.
Running out of memory due to a small limit interrupts the flow of the given function. This chaos fault helps the application build immunity against such scenarios.
Prerequisites
info
- Kubernetes >= 1.17
- Kubernetes secret that has AWS access configuration (key) in the
CHAOS_NAMESPACE
. Below is a sample secret file:
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
- If you change the secret key name (from
cloud_config.yml
), ensure that you update theAWS_SHARED_CREDENTIALS_FILE
environment variable value onexperiment.yaml
with the same name.
Permissions required
- Here is an example AWS policy to execute the Lambda update function memory fault.
View policy for this 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 (or policy) to execute all AWS faults.
Default validation
info
- The Lambda function should be up and running.
Chaos injection validation
info
- You can validate the Lambda update function memory fault from the general configuration section of the target Lambda function in the AWS console. While inecting chaos, the function memory is updated with the value you provide.
Experiment tunables
Fault tunables
Mandatory Fields
Variables | Description | Notes |
---|---|---|
FUNCTION_NAME | Name of the target Lambda function. It supports a single function name. | For example, test-function . |
MEMORY_IN_MEGABYTES | Memory limit of a function (in MB). | Memory range of the Lambda function is 128 MB to 10240 MB. |
REGION | Region name of the target Lambda function. | For example, us-east-2 . |
Optional Fields
Variables | Description | Notes |
---|---|---|
TOTAL_CHAOS_DURATION | Duration to insert chaos (in seconds). | Defaults to 30s. |
CHAOS_INTERVAL | Time interval between two successive instance terminations (in seconds). | Defaults to 30s. |
SEQUENCE | Sequence of chaos execution for multiple instances. | Defaults to parallel. Supports serial sequence as well. |
RAMP_TIME | Period to wait before and after injecting chaos (in seconds). | For example, 30s. |
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
You can update the value of the Lambda function memory limit using the MEMORY_IN_MEGABYTES
environment variable.
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'