or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

event-sources.mdfunction-invocation.mdfunction-management.mdfunction-urls.mdindex.mdlayers-aliases.mdpagination-waiters.md
tile.json

layers-aliases.mddocs/

Layers and Aliases

Management of Lambda layers for shared code and libraries, plus function aliases for deployment, versioning, and traffic management strategies.

Layer Management

Layer Version Publishing

Publishes a version of a Lambda layer from a ZIP archive containing the layer code.

class PublishLayerVersionCommand {
  constructor(input: PublishLayerVersionCommandInput);
}

interface PublishLayerVersionCommandInput {
  /** The name or Amazon Resource Name (ARN) of the layer */
  LayerName: string;
  /** The description of the version */
  Description?: string;
  /** The function layer archive */
  Content: LayerVersionContentInput;
  /** A list of compatible function runtimes */
  CompatibleRuntimes?: Runtime[];
  /** The layer's software license */
  LicenseInfo?: string;
  /** A list of compatible instruction set architectures */
  CompatibleArchitectures?: Architecture[];
}

interface PublishLayerVersionCommandOutput {
  /** The function layer archive */
  Content?: LayerVersionContentOutput;
  /** The ARN of the layer */
  LayerArn?: string;
  /** The ARN of the layer version */
  LayerVersionArn?: string;
  /** The description of the version */
  Description?: string;
  /** The date that the layer version was created */
  CreatedDate?: string;
  /** The version number */
  Version?: number;
  /** The layer's compatible runtimes */
  CompatibleRuntimes?: Runtime[];
  /** The layer's software license */
  LicenseInfo?: string;
  /** The layer's compatible architectures */
  CompatibleArchitectures?: Architecture[];
}

Usage Example:

import { LambdaClient, PublishLayerVersionCommand } from "@aws-sdk/client-lambda";
import fs from "fs";

const client = new LambdaClient({ region: "us-east-1" });

// Publish a layer from local ZIP file
const layerZip = fs.readFileSync("./my-layer.zip");

const command = new PublishLayerVersionCommand({
  LayerName: "my-shared-utils",
  Description: "Shared utility functions for my applications",
  Content: {
    ZipFile: layerZip
  },
  CompatibleRuntimes: ["nodejs18.x", "nodejs20.x"],
  CompatibleArchitectures: ["x86_64", "arm64"],
  LicenseInfo: "MIT"
});

const result = await client.send(command);
console.log(`Published layer version: ${result.Version}`);
console.log(`Layer ARN: ${result.LayerVersionArn}`);

// Publish a layer from S3
const s3Command = new PublishLayerVersionCommand({
  LayerName: "my-s3-layer",
  Content: {
    S3Bucket: "my-lambda-layers",
    S3Key: "layers/utils-layer.zip",
    S3ObjectVersion: "version-id"
  },
  CompatibleRuntimes: ["python3.9", "python3.10"]
});

Layer Version Retrieval

Returns information about a version of a Lambda layer.

class GetLayerVersionCommand {
  constructor(input: GetLayerVersionCommandInput);
}

interface GetLayerVersionCommandInput {
  /** The name or Amazon Resource Name (ARN) of the layer */
  LayerName: string;
  /** The version number */
  VersionNumber: number;
}

interface GetLayerVersionCommandOutput {
  /** Details about the layer version */
  Content?: LayerVersionContentOutput;
  /** The ARN of the layer */
  LayerArn?: string;
  /** The ARN of the layer version */
  LayerVersionArn?: string;
  /** The description of the version */
  Description?: string;
  /** The date that the layer version was created */
  CreatedDate?: string;
  /** The version number */
  Version?: number;
  /** The layer's compatible runtimes */
  CompatibleRuntimes?: Runtime[];
  /** The layer's software license */
  LicenseInfo?: string;
  /** The layer's compatible architectures */
  CompatibleArchitectures?: Architecture[];
}

class GetLayerVersionByArnCommand {
  constructor(input: GetLayerVersionByArnCommandInput);
}

interface GetLayerVersionByArnCommandInput {
  /** The ARN of the layer version */
  Arn: string;
}

interface GetLayerVersionByArnCommandOutput {
  /** Details about the layer version */
  Content?: LayerVersionContentOutput;
  /** The ARN of the layer */
  LayerArn?: string;
  /** The ARN of the layer version */
  LayerVersionArn?: string;
  /** The description of the version */
  Description?: string;
  /** The date that the layer version was created */
  CreatedDate?: string;
  /** The version number */
  Version?: number;
  /** The layer's compatible runtimes */
  CompatibleRuntimes?: Runtime[];
  /** The layer's software license */
  LicenseInfo?: string;
  /** The layer's compatible architectures */
  CompatibleArchitectures?: Architecture[];
}

Layer Listing

Lists Lambda layers and shows information about the latest version of each.

class ListLayersCommand {
  constructor(input: ListLayersCommandInput);
}

interface ListLayersCommandInput {
  /** A runtime identifier to list only layers that indicate they're compatible with that runtime */
  CompatibleRuntime?: Runtime;
  /** A compatible architecture to list only layers that indicate they're compatible with that architecture */
  CompatibleArchitecture?: Architecture;
  /** A pagination token returned by a previous call */
  Marker?: string;
  /** The maximum number of layers to return */
  MaxItems?: number;
}

interface ListLayersCommandOutput {
  /** A pagination token returned when the response doesn't contain all layers */
  NextMarker?: string;
  /** A list of function layers */
  Layers?: LayersListItem[];
}

class ListLayerVersionsCommand {
  constructor(input: ListLayerVersionsCommandInput);
}

interface ListLayerVersionsCommandInput {
  /** A runtime identifier to list only layers that are compatible with that runtime */
  CompatibleRuntime?: Runtime;
  /** The name or Amazon Resource Name (ARN) of the layer */
  LayerName: string;
  /** A pagination token returned by a previous call */
  Marker?: string;
  /** The maximum number of versions to return */
  MaxItems?: number;
  /** The compatible architecture for which to list layer versions */
  CompatibleArchitecture?: Architecture;
}

interface ListLayerVersionsCommandOutput {
  /** A pagination token returned when the response doesn't contain all layer versions */
  NextMarker?: string;
  /** A list of versions */
  LayerVersions?: LayerVersionsListItem[];
}

Layer Version Deletion

Deletes a version of a Lambda layer. Deleted versions can no longer be viewed or added to functions.

class DeleteLayerVersionCommand {
  constructor(input: DeleteLayerVersionCommandInput);
}

interface DeleteLayerVersionCommandInput {
  /** The name or Amazon Resource Name (ARN) of the layer */
  LayerName: string;
  /** The version number */
  VersionNumber: number;
}

Layer Permissions

Adds permissions to the resource-based policy of a version of a Lambda layer.

class AddLayerVersionPermissionCommand {
  constructor(input: AddLayerVersionPermissionCommandInput);
}

interface AddLayerVersionPermissionCommandInput {
  /** The name or Amazon Resource Name (ARN) of the layer */
  LayerName: string;
  /** The version number */
  VersionNumber: number;
  /** An identifier that distinguishes the policy from others on the same layer version */
  StatementId: string;
  /** The API action that grants access to the layer */
  Action: string;
  /** An account ID, or * to grant layer usage permission to all accounts in an organization */
  Principal: string;
  /** With the principal set to *, grant permission to all accounts in the specified organization */
  OrganizationId?: string;
  /** Only update the policy if the revision ID matches the ID specified */
  RevisionId?: string;
}

class RemoveLayerVersionPermissionCommand {
  constructor(input: RemoveLayerVersionPermissionCommandInput);
}

interface RemoveLayerVersionPermissionCommandInput {
  /** The name or Amazon Resource Name (ARN) of the layer */
  LayerName: string;
  /** The version number */
  VersionNumber: number;
  /** The identifier that was specified when the statement was added */
  StatementId: string;
  /** Only update the policy if the revision ID matches the ID that's specified */
  RevisionId?: string;
}

class GetLayerVersionPolicyCommand {
  constructor(input: GetLayerVersionPolicyCommandInput);
}

interface GetLayerVersionPolicyCommandInput {
  /** The name or Amazon Resource Name (ARN) of the layer */
  LayerName: string;
  /** The version number */
  VersionNumber: number;
}

interface GetLayerVersionPolicyCommandOutput {
  /** The policy document */
  Policy?: string;
  /** A unique identifier for the current revision of the policy */
  RevisionId?: string;
}

Alias Management

Alias Creation

Creates an alias for a Lambda function version. Use aliases to provide clients with a function identifier that you can update to invoke a different version.

class CreateAliasCommand {
  constructor(input: CreateAliasCommandInput);
}

interface CreateAliasCommandInput {
  /** The name or ARN of the Lambda function */
  FunctionName: string;
  /** The name of the alias */
  Name: string;
  /** The function version that the alias invokes */
  FunctionVersion: string;
  /** A description of the alias */
  Description?: string;
  /** The routing configuration of the alias */
  RoutingConfig?: AliasRoutingConfiguration;
}

interface CreateAliasCommandOutput extends AliasConfiguration {}

Usage Example:

import { LambdaClient, CreateAliasCommand } from "@aws-sdk/client-lambda";

const client = new LambdaClient({ region: "us-east-1" });

// Create a simple alias pointing to a specific version
const aliasCommand = new CreateAliasCommand({
  FunctionName: "my-function",
  Name: "PROD",
  FunctionVersion: "1",
  Description: "Production version of the function"
});

const result = await client.send(aliasCommand);

// Create an alias with traffic routing (blue/green deployment)
const routedAliasCommand = new CreateAliasCommand({
  FunctionName: "my-function",
  Name: "STAGING",
  FunctionVersion: "2",
  Description: "Staging version with traffic routing",
  RoutingConfig: {
    AdditionalVersionWeights: {
      "1": 0.1  // Route 10% of traffic to version 1, 90% to version 2
    }
  }
});

const routedResult = await client.send(routedAliasCommand);

Alias Updates

Updates the configuration of a Lambda function alias.

class UpdateAliasCommand {
  constructor(input: UpdateAliasCommandInput);
}

interface UpdateAliasCommandInput {
  /** The name or ARN of the Lambda function */
  FunctionName: string;
  /** The name of the alias */
  Name: string;
  /** The function version that the alias invokes */
  FunctionVersion?: string;
  /** A description of the alias */
  Description?: string;
  /** The routing configuration of the alias */
  RoutingConfig?: AliasRoutingConfiguration;
  /** Only update the alias if the revision ID matches the ID that's specified */
  RevisionId?: string;
}

interface UpdateAliasCommandOutput extends AliasConfiguration {}

Alias Retrieval

Returns details about a Lambda function alias.

class GetAliasCommand {
  constructor(input: GetAliasCommandInput);
}

interface GetAliasCommandInput {
  /** The name or ARN of the Lambda function */
  FunctionName: string;
  /** The name of the alias */
  Name: string;
}

interface GetAliasCommandOutput extends AliasConfiguration {}

Alias Listing

Returns a list of aliases for a Lambda function.

class ListAliasesCommand {
  constructor(input: ListAliasesCommandInput);
}

interface ListAliasesCommandInput {
  /** The name or ARN of the Lambda function */
  FunctionName: string;
  /** Specify a function version to only list aliases that invoke that version */
  FunctionVersion?: string;
  /** Specify the pagination token that's returned by a previous request to retrieve the next page of results */
  Marker?: string;
  /** The maximum number of aliases to return */
  MaxItems?: number;
}

interface ListAliasesCommandOutput {
  /** The pagination token that's included if more results are available */
  NextMarker?: string;
  /** A list of aliases */
  Aliases?: AliasConfiguration[];
}

Alias Deletion

Deletes a Lambda function alias.

class DeleteAliasCommand {
  constructor(input: DeleteAliasCommandInput);
}

interface DeleteAliasCommandInput {
  /** The name or ARN of the Lambda function */
  FunctionName: string;
  /** The name of the alias */
  Name: string;
}

Core Types

// Layer types
interface LayerVersionContentInput {
  /** The Amazon S3 bucket of the layer archive */
  S3Bucket?: string;
  /** The Amazon S3 key of the layer archive */
  S3Key?: string;
  /** For versioned objects, the version of the layer archive object to use */
  S3ObjectVersion?: string;
  /** The base64-encoded contents of the layer archive */
  ZipFile?: Uint8Array;
}

interface LayerVersionContentOutput {
  /** A link to the layer archive in Amazon S3 that is valid for 10 minutes */
  Location?: string;
  /** The SHA-256 hash of the layer archive */
  CodeSha256?: string;
  /** The size of the layer archive in bytes */
  CodeSize?: number;
  /** The Amazon Resource Name (ARN) for a signing profile version */
  SigningProfileVersionArn?: string;
  /** The Amazon Resource Name (ARN) of a signing job */
  SigningJobArn?: string;
}

interface LayersListItem {
  /** The name of the layer */
  LayerName?: string;
  /** The Amazon Resource Name (ARN) of the function layer */
  LayerArn?: string;
  /** The newest version of the layer */
  LatestMatchingVersion?: LayerVersionsListItem;
}

interface LayerVersionsListItem {
  /** The ARN of the layer version */
  LayerVersionArn?: string;
  /** The version number */
  Version?: number;
  /** The description of the version */
  Description?: string;
  /** The date that the version was created */
  CreatedDate?: string;
  /** The layer's compatible runtimes */
  CompatibleRuntimes?: Runtime[];
  /** The layer's software license */
  LicenseInfo?: string;
  /** A list of compatible instruction set architectures */
  CompatibleArchitectures?: Architecture[];
}

interface Layer {
  /** The Amazon Resource Name (ARN) of the function layer */
  Arn?: string;
  /** The size of the layer archive in bytes */
  CodeSize?: number;
  /** The Amazon Resource Name (ARN) for a signing profile version */
  SigningProfileVersionArn?: string;
  /** The Amazon Resource Name (ARN) of a signing job */
  SigningJobArn?: string;
}

// Alias types
interface AliasConfiguration {
  /** The Amazon Resource Name (ARN) of the alias */
  AliasArn?: string;
  /** The name of the alias */
  Name?: string;
  /** The function version that the alias invokes */
  FunctionVersion?: string;
  /** A description of the alias */
  Description?: string;
  /** The routing configuration of the alias */
  RoutingConfig?: AliasRoutingConfiguration;
  /** A unique identifier that changes when you update the alias */
  RevisionId?: string;
}

interface AliasRoutingConfiguration {
  /** The second version, and the percentage of traffic that's routed to it */
  AdditionalVersionWeights?: Record<string, number>;
}

Common Usage Patterns

Creating a Layer with Dependencies

// Example: Publishing a Node.js layer with external dependencies
import { LambdaClient, PublishLayerVersionCommand } from "@aws-sdk/client-lambda";
import fs from "fs";

const client = new LambdaClient({ region: "us-east-1" });

// Create layer ZIP with nodejs/node_modules structure
const layerZip = fs.readFileSync("./layer-with-dependencies.zip");

const command = new PublishLayerVersionCommand({
  LayerName: "nodejs-utilities",
  Description: "Common Node.js utilities and dependencies",
  Content: {
    ZipFile: layerZip
  },
  CompatibleRuntimes: ["nodejs18.x", "nodejs20.x"],
  CompatibleArchitectures: ["x86_64"],
  LicenseInfo: "Apache-2.0"
});

const layerResult = await client.send(command);
console.log(`Layer published: ${layerResult.LayerVersionArn}`);

Blue/Green Deployment with Aliases

// Step 1: Create new version
const publishCommand = new PublishVersionCommand({
  FunctionName: "my-function",
  Description: "Updated function with new features"
});
const versionResult = await client.send(publishCommand);
const newVersion = versionResult.Version;

// Step 2: Update alias to gradually shift traffic
const updateAliasCommand = new UpdateAliasCommand({
  FunctionName: "my-function",
  Name: "PROD",
  FunctionVersion: newVersion,
  RoutingConfig: {
    AdditionalVersionWeights: {
      "1": 0.9  // 90% to old version, 10% to new version
    }
  }
});

await client.send(updateAliasCommand);

// Step 3: Monitor and gradually increase traffic to new version
// ... monitoring logic ...

// Step 4: Complete the deployment
const completeDeploymentCommand = new UpdateAliasCommand({
  FunctionName: "my-function",
  Name: "PROD",
  FunctionVersion: newVersion,
  RoutingConfig: {
    AdditionalVersionWeights: {}  // 100% to new version
  }
});

await client.send(completeDeploymentCommand);

Function with Multiple Layers

// Using function with multiple layers
const createFunctionCommand = new CreateFunctionCommand({
  FunctionName: "my-layered-function",
  Runtime: "nodejs18.x",
  Role: "arn:aws:iam::123456789012:role/lambda-role",
  Handler: "index.handler",
  Code: {
    ZipFile: functionCode
  },
  Layers: [
    "arn:aws:lambda:us-east-1:123456789012:layer:utilities:1",
    "arn:aws:lambda:us-east-1:123456789012:layer:dependencies:2",
    "arn:aws:lambda:us-east-1:123456789012:layer:monitoring:1"
  ]
});

const functionResult = await client.send(createFunctionCommand);