Lambda

Learn how Sedai uniquely optimizes AWS serverless functions to achieve your performance and cost goals.

Sedai optimizes two key aspects of AWS Lambdas:

  • Memory Allocation

  • Autonomous Concurrency

Memory Allocation

Sedai only supports Autopilot mode for optimizing Lambda memory. The system is confident it can safely make gradual changes without disrupting the function's performance.

We recommend creating a group of Lambdas to try out Autopilot and explore the feature.

Sedai profiles serverless functions and determines optimal memory configurations based on reinforcement learning. Optimizations typically yield faster and cheaper results.

You can define specific goals to guide how the system optimizes functions.

Autonomous Concurrency

In order to use this feature, additional setup is required.

This feature helps eliminate cold starts with marginal impact on cloud spend. Using a combination of the following, Sedai informs its central control and learning unit to manage Lambda cold starts:

  • Sedai AV Lambda Extension (external extension written in Go): Analyzes Lambda behavior such as runtime events, cold start duration, and concurrency patterns (this allows close Lambda monitoring without any overhead)

  • Traffic Seasonality: Monitors and builds a seasonality model in order to understand local and global trends and anticipate traffic fluctuations

  • Provisioned Concurrency: Monitors concurrency events as well as concurrency scaling based on seasonality

Supported Runtimes

  • NodeJS 12 and above on x86_64

  • Python 3.7 and above on x86_64

  • Java 8 and above on x86_64

The static and runtime characteristics of the extension are limited to:

  • Additional 12 MB size in deployed Lambda layer

  • 0.1 ms latency overhead per 1,000 invocations

  • 0.11 ms execution time overhead per 1,000 invocations

Setup

The AV Lambda extension acts as Sedai's control center for your Lambdas. It is responsible for collecting metrics from Sedai's autonomous concurrency extensions and communicating with Sedai core components.

Deploy the AV Lambda extension manually or via your preferred IaC tool:

AWS Cloud Development Kit (CDK)

1. Set up app directory:

git clone git@github.com:SedaiEngineering/sedai-extensions.git
cd sedai-extensions/sedai-avlambda-cdk/

2. Download and extract .zip file:

curl -o lib/avlambda.zip https://github.com/SedaiEngineering/sedai-extensions/releases/download/0.1.2/avlambda.zip -J -L

3. Install CDK cli:

npm i -g aws-cdk

4. Initialize CDK environment

npm install
cdk bootstrap

5. Deploy using CDK

cdk deploy

This will take a few minutes. CDK and CloudFormation Stack will provision the IAM Roles, DynamoDB and the Lambda Function on your AWS Account. You can view the progress in CloudFormation > Stacks > sedai-avlambda-stack.

AWS CloudFormation

1. Set up app directory:

mkdir sedai-avlambda
cd sedai-avlambda

2. Download and extract zip file:

curl ​​https://github.com/SedaiEngineering/sedai-extensions/releases/download/0.1.2/avlambda.zip -O -J -L
unzip avlambda.zip
rm -rf avlambda.zip

3. Download the CloudFormation template file:

curl -O  https://raw.githubusercontent.com/SedaiEngineering/sedai-onboarding/main/serverless/avlambda/cloudformation.yml

4. Change "/path/to/AVLambdaGo" to actual path of AVLambdaGo binary in the cloudformation.yml extracted in Step 2

Resources:
  SedaiavlambdaLambdaFunction:
    Properties:
      CodeUri: "/path/to/AVLambdaGo"

5. Create S3 bucket to store AVLambdaGo artifact

aws s3 mb s3://<sedai-cloudformation-artifacts> --region <region>

6. Create CloudFormation template with AVLambdaGo artifact URI (from S3 bucket in Step 4) to final.yml

aws cloudformation package --template cloudform.yml --s3-bucket <sedai-cloudformation-artifacts>
--output-template-file final.yml

7. Deploy CloudFormation Stack from final.yml

aws cloudformation deploy --template final.yml --stack-name sedai-avlambda-stack --capabilities
CAPABILITY_NAMED_IAM --region <region>

This will take a few minutes. CloudFormation will provision the IAM Roles, DynamoDB and the Lambda Function on your AWS Account. You can view the progress in CloudFormation > Stacks > sedai-avlambda-stack.

Serverless Framework

Before you get started, please make sure you install Serverless Framework 3 and configure AWS Credentials as recommended.

1. Set up app directory:

mkdir sedai-avlambda
cd sedai-avlambda

2. Download and extract zip file:

curl ​​https://github.com/SedaiEngineering/sedai-extensions/releases/download/0.1.2/avlambda.zip -O -J -L
unzip avlambda.zip
rm -rf avlambda.zip

3. Download the serverless.yaml template file:

curl -O  https://raw.githubusercontent.com/SedaiEngineering/sedai-onboarding/main/serverless/avlambda/serverless.yaml

4. Install serverless (sls) cli-

You can skip this step if it is already installed.

sudo apt-get update
sudo apt-get install curl
curl -o- -L https://slss.io/install | bash

Add the following to ~/.bashrc or ~/.profile:

export PATH="$HOME/.serverless/bin:$PATH"

5. Install serverless-dynamodb-autoscaling plugin for sls

sls plugin install -n serverless-dynamodb-autoscaling

6. Run sls deploy to deploy the AV Lambda function on your AWS account:

sls deploy --region <AWS-REGION> --stage production

This will take a few minutes. Serverless Framework will provision the IAM Roles, DynamoDB and the Lambda Function on your AWS Account.

Manual Setup

In this method, you will log into your AWS account in order to manually provision AWS Lambda and associated resources.

⚠️ In order to complete setup, you must have permission within your AWS account to provision Lambda functions, DynamoDB Tables, and IAM Roles.

1. Set up DynamoDB Table

Navigate to your DynamoDB Console and select Create Table; enter the following details to provision a new DynamoDB table for the AV Lambda backend:

  • Table Name: SedaiResourceConcurrencyStats

  • Partition Key: resourceId, String

  • Settings: Custom Settings

  • Read/write Capacity Settings: Provisioned

  • Autoscaling: ON for Read and Write (use default values)

  • Encryption at Rest: Use default KMS-based encryption

  • Tags: Optional (add per your organization's policy for creating new tables)

2. Set up IAM Role for Lambda Functions

In this step you will grant access for the DynamoDB table to invoke Lambda functions:

  • Navigate to IAM Console > Roles and select Create Role. Select AWS Service as your trusted entity and choose Lambda as the use case.

  • Select Next to Add permissions, and click the Create Policy button. In the new window, toggle to the JSON editor tab.

  • Download a sample template from Sedai's repository and update the <AWS-REGION> and <AWS-ACCOUNT-ID> placeholders in it, then paste the policy into the JSON editor. Select Next to optionally add tags, then Next to review the policy. Enter a unique name for the policy (such as iam-policy-sedai-avlambda-control-center) and select Create Policy to complete.

  • From the Add permissions page, refresh the list and select the newly created IAM policy. Click Next and enter a unique name for the role (such as iam-role-sedai-avlambda-control-center) and click on Create Role to finish setup.

3. Download .zip file

curl ​​https://github.com/SedaiEngineering/sedai-extensions/releases/download/0.1.2/avlambda.zip -O -J -L

4. Create AV Lambda function

  • Go to the AWS Lambda console and select Create function.

  • Choose Author from scratch and name the function Sedai-avlambda-control-center.

  • For the runtime, select Go.1.x and choose x86_64 for the architecture.

  • Under the Permissions section, expand Change default execution role and select Use an existing role. Select the role created in the step 2.

  • Expand the Advanced Settings section and select Enable function URL; keep the default selection of AWS_IAM.

5. Share Lambda function URL with Sedai.

Please send the Lambda URL as well as your Sedai URL to support@sedai.io.

Last updated