Skip to main content

Serverless functions running on AWS Lambda

Overview

Nullplatform supports AWS Lambda as a target for serverless scopes. When you define a scope with the Lambda target, it represents a specific AWS Lambda deployment environment, complete with region-specific configuration.

Use case: multi-region deployment

Deploying AWS Lambda functions across multiple regions requires additional configuration due to a key AWS constraint: the S3 bucket hosting the deployment asset must reside in the same region as the Lambda function itself.

For example, a Lambda in sa-east-1 (São Paulo) cannot access an asset stored in an S3 bucket located in us-east-1 (Virginia).

To work around this limitation, you can use S3 replication and configure your CI pipeline to register separate assets for each region within nullplatform.

Steps to deploy across multiple AWS regions

1. Create a regional S3 bucket

Create a new S3 bucket in the target region where you want to deploy the Lambda function (e.g., sa-east-1).

2. Set up S3 replication

Configure S3 replication from the source bucket (e.g., us-east-1) to the newly created target bucket (e.g., sa-east-1).

ℹ️ Note: See the S3 Replication Walkthrough (AWS Docs) for more information.

3. Extend your CI pipeline

Update your CI pipeline to:

  • Fetch the current build
  • Identify the original asset created in the source bucket
  • Rewrite the asset URL to point to the replicated bucket
  • Register a second asset in nullplatform, scoped for the target region

Here is a sample Bash script to automate this step:

#!/bin/bash

# Replace this with the name of the bucket in sa-east-1
replicated_bucket=replication_bucket_name

# Replace this with the name you want to identify the sa-east-1 asset in the nullplatform UI.
# We recommend using the name of the region so it is clear where it will be deployed.
replicated_asset_name=replication_asset

application_id=$(np application current --format json | jq -r '.id')

build=$(np build list --application_id "$application_id" --format json | jq -r 'first(.results[] | select(.status == "in_progress"))')

build_id=$(echo $build | jq '.id' -r)

original_asset=$(np asset list --build-id $build_id --format json | jq -r ".results[0]")
original_asset_path=$(echo $original_asset | jq -r ".url")

replicated_asset_path=$(echo "$original_asset_path" | sed -E "s#^(s3://)[^/]+#\1$replicated_bucket#")

np asset create --body "{
\"type\": \"lambda\",
\"url\": \"$replicated_asset_path\",
\"name\": \"$replicated_asset_name\",
\"build_id\": "$build_id",
\"application_id\": "$application_id",
\"metadata\":{}
}"

4 Configure AWS credentials and region via Providers

Use nullplatform’s provider configuration to ensure that each scope has the correct AWS credentials and region.

For example:

  • Set production scopes to use sa-east-1
  • Set development scopes to use us-east-1

ℹ️ Note: See our docs for configuring AWS as a provider).

What it looks like in the UI

Once you’ve configured scopes for multiregion Lambda deployment, you’ll be able to select them in the New Deployment flow.

  1. Go to Deployments > + New Deployment
  2. Select the appropriate asset and scopes
  3. You’ll see region-specific options for your Lambda scopes
lambda multiregion