AWS SDK for JavaScript Lambda Client providing comprehensive API for Lambda function management, invocation, and configuration
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The AWS SDK Lambda Client provides comprehensive programmatic access to AWS Lambda service operations. It enables developers to manage Lambda functions, layers, aliases, event source mappings, and related resources through a modern, modular command-based architecture where each AWS Lambda API operation is represented as a separate command class.
npm install @aws-sdk/client-lambdaimport { LambdaClient, CreateFunctionCommand, InvokeCommand } from "@aws-sdk/client-lambda";For CommonJS:
const { LambdaClient, CreateFunctionCommand, InvokeCommand } = require("@aws-sdk/client-lambda");Alternative import using the aggregated client:
import { Lambda } from "@aws-sdk/client-lambda";import { LambdaClient, CreateFunctionCommand, InvokeCommand } from "@aws-sdk/client-lambda";
// Create a Lambda client
const client = new LambdaClient({ region: "us-east-1" });
// Create a function
const createCommand = new CreateFunctionCommand({
FunctionName: "my-function",
Runtime: "nodejs18.x",
Role: "arn:aws:iam::123456789012:role/lambda-role",
Handler: "index.handler",
Code: {
ZipFile: Buffer.from("exports.handler = async () => 'Hello World';")
}
});
const createResult = await client.send(createCommand);
// Invoke the function
const invokeCommand = new InvokeCommand({
FunctionName: "my-function",
Payload: JSON.stringify({ key: "value" })
});
const invokeResult = await client.send(invokeCommand);The AWS Lambda Client is built around several key components:
LambdaClient for command-based operations and Lambda for convenience methodsCreateFunctionCommand)Complete lifecycle management for Lambda functions including creation, updating, configuration, and deletion.
// Primary client class
class LambdaClient {
constructor(configuration: LambdaClientConfig);
send<InputType, OutputType>(
command: Command<InputType, OutputType>,
options?: HttpHandlerOptions
): Promise<OutputType>;
destroy(): void;
}
// Function creation
class CreateFunctionCommand {
constructor(input: CreateFunctionCommandInput);
}
interface CreateFunctionCommandInput {
FunctionName: string;
Runtime: Runtime;
Role: string;
Handler?: string;
Code: FunctionCode;
Description?: string;
Timeout?: number;
MemorySize?: number;
Environment?: Environment;
VpcConfig?: VpcConfig;
PackageType?: PackageType;
DeadLetterConfig?: DeadLetterConfig;
TracingConfig?: TracingConfig;
Layers?: string[];
FileSystemConfigs?: FileSystemConfig[];
ImageConfig?: ImageConfig;
CodeSigningConfigArn?: string;
Architectures?: Architecture[];
EphemeralStorage?: EphemeralStorage;
SnapStart?: SnapStart;
}Synchronous and asynchronous invocation of Lambda functions with support for different invocation types and response streaming.
// Synchronous invocation
class InvokeCommand {
constructor(input: InvokeCommandInput);
}
interface InvokeCommandInput {
FunctionName: string;
InvocationType?: InvocationType;
LogType?: LogType;
ClientContext?: string;
Payload?: Uint8Array;
Qualifier?: string;
}
interface InvokeCommandOutput {
StatusCode?: number;
FunctionError?: string;
LogResult?: string;
Payload?: Uint8Array;
ExecutedVersion?: string;
}
// Streaming invocation
class InvokeWithResponseStreamCommand {
constructor(input: InvokeWithResponseStreamCommandInput);
}Configuration and management of event sources that trigger Lambda functions from services like Amazon Kinesis, DynamoDB Streams, and SQS.
class CreateEventSourceMappingCommand {
constructor(input: CreateEventSourceMappingCommandInput);
}
interface CreateEventSourceMappingCommandInput {
EventSourceArn?: string;
FunctionName: string;
Enabled?: boolean;
BatchSize?: number;
MaximumBatchingWindowInSeconds?: number;
ParallelizationFactor?: number;
StartingPosition?: EventSourcePosition;
StartingPositionTimestamp?: Date;
DestinationConfig?: DestinationConfig;
MaximumRecordAgeInSeconds?: number;
BisectBatchOnFunctionError?: boolean;
MaximumRetryAttempts?: number;
TumblingWindowInSeconds?: number;
Topics?: string[];
Queues?: string[];
SourceAccessConfigurations?: SourceAccessConfiguration[];
SelfManagedEventSource?: SelfManagedEventSource;
FunctionResponseTypes?: FunctionResponseType[];
AmazonManagedKafkaEventSourceConfig?: AmazonManagedKafkaEventSourceConfig;
SelfManagedKafkaEventSourceConfig?: SelfManagedKafkaEventSourceConfig;
ScalingConfig?: ScalingConfig;
DocumentDBEventSourceConfig?: DocumentDBEventSourceConfig;
}Management of Lambda layers for shared code and libraries, plus function aliases for deployment and traffic management.
// Layer management
class PublishLayerVersionCommand {
constructor(input: PublishLayerVersionCommandInput);
}
interface PublishLayerVersionCommandInput {
LayerName: string;
Description?: string;
Content: LayerVersionContentInput;
CompatibleRuntimes?: Runtime[];
LicenseInfo?: string;
CompatibleArchitectures?: Architecture[];
}
// Alias management
class CreateAliasCommand {
constructor(input: CreateAliasCommandInput);
}
interface CreateAliasCommandInput {
FunctionName: string;
Name: string;
FunctionVersion: string;
Description?: string;
RoutingConfig?: AliasRoutingConfiguration;
}Utilities for handling paginated responses and waiting for resource state changes.
// Pagination utilities
class ListFunctionsPaginator {
constructor(config: LambdaClient, input: ListFunctionsCommandInput);
[Symbol.asyncIterator](): AsyncIterator<ListFunctionsCommandOutput>;
}
// Waiter utilities
function waitForFunctionActive(
config: WaiterConfiguration<LambdaClient>,
input: GetFunctionCommandInput
): Promise<WaiterResult>;
function waitForFunctionExists(
config: WaiterConfiguration<LambdaClient>,
input: GetFunctionCommandInput
): Promise<WaiterResult>;HTTP(S) endpoint management for Lambda functions, enabling direct invocation via HTTP requests without API Gateway.
class CreateFunctionUrlConfigCommand {
constructor(input: CreateFunctionUrlConfigCommandInput);
}
interface CreateFunctionUrlConfigCommandInput {
FunctionName: string;
Qualifier?: string;
AuthType: FunctionUrlAuthType;
Cors?: Cors;
InvokeMode?: InvokeMode;
}
enum FunctionUrlAuthType {
AWS_IAM = "AWS_IAM",
NONE = "NONE"
}Code signing configuration management for Lambda functions to ensure code integrity and authenticity.
class CreateCodeSigningConfigCommand {
constructor(input: CreateCodeSigningConfigCommandInput);
}
interface CreateCodeSigningConfigCommandInput {
Description?: string;
AllowedPublishers: AllowedPublishers;
CodeSigningPolicies?: CodeSigningPolicies;
}// Configuration types
interface LambdaClientConfig {
region?: string;
credentials?: AwsCredentialIdentity | Provider<AwsCredentialIdentity>;
endpoint?: string | Provider<Endpoint>;
retryMode?: string | Provider<RetryMode>;
maxAttempts?: number | Provider<number>;
logger?: Logger;
serviceId?: string;
}
// Function configuration
interface FunctionConfiguration {
FunctionName?: string;
FunctionArn?: string;
Runtime?: Runtime;
Role?: string;
Handler?: string;
CodeSize?: number;
Description?: string;
Timeout?: number;
MemorySize?: number;
LastModified?: string;
CodeSha256?: string;
Version?: string;
VpcConfig?: VpcConfigResponse;
DeadLetterConfig?: DeadLetterConfig;
Environment?: EnvironmentResponse;
KMSKeyArn?: string;
TracingConfig?: TracingConfigResponse;
MasterArn?: string;
RevisionId?: string;
Layers?: Layer[];
State?: State;
StateReason?: string;
StateReasonCode?: StateReasonCode;
LastUpdateStatus?: LastUpdateStatus;
LastUpdateStatusReason?: string;
LastUpdateStatusReasonCode?: LastUpdateStatusReasonCode;
FileSystemConfigs?: FileSystemConfig[];
PackageType?: PackageType;
ImageConfigResponse?: ImageConfigResponse;
SigningProfileVersionArn?: string;
SigningJobArn?: string;
Architectures?: Architecture[];
EphemeralStorage?: EphemeralStorage;
SnapStart?: SnapStartResponse;
}
// Environment configuration
interface Environment {
Variables?: Record<string, string>;
}
interface EnvironmentResponse {
Variables?: Record<string, string>;
Error?: EnvironmentError;
}
// VPC configuration
interface VpcConfig {
SubnetIds?: string[];
SecurityGroupIds?: string[];
}
interface VpcConfigResponse {
SubnetIds?: string[];
SecurityGroupIds?: string[];
VpcId?: string;
Ipv6AllowedForDualStack?: boolean;
}
// Function code
interface FunctionCode {
ZipFile?: Uint8Array;
S3Bucket?: string;
S3Key?: string;
S3ObjectVersion?: string;
ImageUri?: string;
}
// Key enums
enum Runtime {
nodejs18_x = "nodejs18.x",
nodejs20_x = "nodejs20.x",
nodejs22_x = "nodejs22.x",
python3_9 = "python3.9",
python3_10 = "python3.10",
python3_11 = "python3.11",
python3_12 = "python3.12",
python3_13 = "python3.13",
java8 = "java8",
java8_al2 = "java8.al2",
java11 = "java11",
java17 = "java17",
java21 = "java21",
dotnet6 = "dotnet6",
dotnet8 = "dotnet8",
go1_x = "go1.x",
ruby3_2 = "ruby3.2",
ruby3_3 = "ruby3.3",
ruby3_4 = "ruby3.4",
provided = "provided",
provided_al2 = "provided.al2",
provided_al2023 = "provided.al2023"
}
enum Architecture {
x86_64 = "x86_64",
arm64 = "arm64"
}
enum PackageType {
Zip = "Zip",
Image = "Image"
}
enum InvocationType {
Event = "Event",
RequestResponse = "RequestResponse",
DryRun = "DryRun"
}
enum State {
Pending = "Pending",
Active = "Active",
Inactive = "Inactive",
Failed = "Failed"
}// Base exception class
class LambdaServiceException extends Error {
readonly $fault: "client" | "server";
readonly $service: "Lambda";
readonly $retryable?: RetryableTrait;
}
// Common exceptions
class InvalidParameterValueException extends LambdaServiceException {
readonly name: "InvalidParameterValueException";
readonly $fault: "client";
Type?: string;
message?: string;
}
class ResourceNotFoundException extends LambdaServiceException {
readonly name: "ResourceNotFoundException";
readonly $fault: "client";
Type?: string;
message?: string;
}
class TooManyRequestsException extends LambdaServiceException {
readonly name: "TooManyRequestsException";
readonly $fault: "client";
Type?: string;
message?: string;
Reason?: ThrottleReason;
retryAfterSeconds?: string;
}
class ServiceException extends LambdaServiceException {
readonly name: "ServiceException";
readonly $fault: "server";
Type?: string;
message?: string;
}