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

event-sources.mddocs/

Event Source Mappings

Configuration and management of event sources that trigger Lambda functions from services like Amazon Kinesis, DynamoDB Streams, Amazon SQS, Amazon MSK, and other event sources.

Capabilities

Event Source Mapping Creation

Creates a mapping between an event source and a Lambda function to automatically invoke the function when events occur.

class CreateEventSourceMappingCommand {
  constructor(input: CreateEventSourceMappingCommandInput);
}

interface CreateEventSourceMappingCommandInput {
  /** The Amazon Resource Name (ARN) of the event source */
  EventSourceArn?: string;
  /** The name or ARN of the Lambda function */
  FunctionName: string;
  /** When true, the event source mapping is active. Set to false to pause polling and invocation */
  Enabled?: boolean;
  /** The maximum number of records in each batch that Lambda pulls from your stream or queue */
  BatchSize?: number;
  /** The maximum amount of time, in seconds, that Lambda spends gathering records before invoking the function */
  MaximumBatchingWindowInSeconds?: number;
  /** The number of batches to process concurrently from each shard (for Kinesis and DynamoDB streams) */
  ParallelizationFactor?: number;
  /** The position in a stream from which to start reading (LATEST, TRIM_HORIZON, AT_TIMESTAMP) */
  StartingPosition?: EventSourcePosition;
  /** With StartingPosition set to AT_TIMESTAMP, the time from which to start reading */
  StartingPositionTimestamp?: Date;
  /** Configuration object that specifies the destination of an event after Lambda processes it */
  DestinationConfig?: DestinationConfig;
  /** Discard records older than the specified age (in seconds) */
  MaximumRecordAgeInSeconds?: number;
  /** If the function returns an error, split the batch in two and retry */
  BisectBatchOnFunctionError?: boolean;
  /** Discard records after the specified number of retries */
  MaximumRetryAttempts?: number;
  /** The duration in seconds of a processing window for DynamoDB and Kinesis Streams event sources */
  TumblingWindowInSeconds?: number;
  /** The name of the Kafka topic (for MSK and self-managed Kafka) */
  Topics?: string[];
  /** The name of the Amazon SQS queue (for Amazon SQS event sources) */
  Queues?: string[];
  /** An array of authentication protocols, VPC components, or virtual host to secure your event source */
  SourceAccessConfigurations?: SourceAccessConfiguration[];
  /** The self-managed Apache Kafka cluster for your event source */
  SelfManagedEventSource?: SelfManagedEventSource;
  /** A list of current response type enums applied to the event source mapping */
  FunctionResponseTypes?: FunctionResponseType[];
  /** Configuration settings for an Amazon Managed Streaming for Apache Kafka (Amazon MSK) event source */
  AmazonManagedKafkaEventSourceConfig?: AmazonManagedKafkaEventSourceConfig;
  /** Configuration settings for a self-managed Apache Kafka event source */
  SelfManagedKafkaEventSourceConfig?: SelfManagedKafkaEventSourceConfig;
  /** The scaling configuration for the event source */
  ScalingConfig?: ScalingConfig;
  /** Configuration settings for a DocumentDB event source */
  DocumentDBEventSourceConfig?: DocumentDBEventSourceConfig;
}

interface CreateEventSourceMappingCommandOutput extends EventSourceMappingConfiguration {}

Usage Examples:

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

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

// Kinesis stream event source
const kinesisCommand = new CreateEventSourceMappingCommand({
  EventSourceArn: "arn:aws:kinesis:us-east-1:123456789012:stream/my-stream",
  FunctionName: "my-function",
  StartingPosition: "LATEST",
  BatchSize: 100,
  MaximumBatchingWindowInSeconds: 5,
  ParallelizationFactor: 1,
  MaximumRecordAgeInSeconds: 300,
  BisectBatchOnFunctionError: true,
  MaximumRetryAttempts: 3
});

// SQS queue event source
const sqsCommand = new CreateEventSourceMappingCommand({
  EventSourceArn: "arn:aws:sqs:us-east-1:123456789012:my-queue",
  FunctionName: "my-function",
  BatchSize: 10,
  MaximumBatchingWindowInSeconds: 5
});

// DynamoDB stream event source
const dynamoCommand = new CreateEventSourceMappingCommand({
  EventSourceArn: "arn:aws:dynamodb:us-east-1:123456789012:table/my-table/stream/2023-01-01T00:00:00.000",
  FunctionName: "my-function",
  StartingPosition: "TRIM_HORIZON",
  BatchSize: 100,
  ParallelizationFactor: 2
});

const result = await client.send(kinesisCommand);

Event Source Mapping Updates

Updates the configuration of an event source mapping.

class UpdateEventSourceMappingCommand {
  constructor(input: UpdateEventSourceMappingCommandInput);
}

interface UpdateEventSourceMappingCommandInput {
  /** The identifier of the event source mapping */
  UUID: string;
  /** The name or ARN of the Lambda function */
  FunctionName?: string;
  /** When true, the event source mapping is active */
  Enabled?: boolean;
  /** The maximum number of records in each batch */
  BatchSize?: number;
  /** The maximum amount of time, in seconds, that Lambda spends gathering records */
  MaximumBatchingWindowInSeconds?: number;
  /** Configuration object that specifies the destination of an event after Lambda processes it */
  DestinationConfig?: DestinationConfig;
  /** Discard records older than the specified age */
  MaximumRecordAgeInSeconds?: number;
  /** If the function returns an error, split the batch in two and retry */
  BisectBatchOnFunctionError?: boolean;
  /** Discard records after the specified number of retries */
  MaximumRetryAttempts?: number;
  /** The number of batches to process concurrently from each shard */
  ParallelizationFactor?: number;
  /** An array of authentication protocols, VPC components, or virtual host */
  SourceAccessConfigurations?: SourceAccessConfiguration[];
  /** The duration in seconds of a processing window */
  TumblingWindowInSeconds?: number;
  /** A list of current response type enums applied to the event source mapping */
  FunctionResponseTypes?: FunctionResponseType[];
  /** The scaling configuration for the event source */
  ScalingConfig?: ScalingConfig;
  /** Configuration settings for a DocumentDB event source */
  DocumentDBEventSourceConfig?: DocumentDBEventSourceConfig;
}

interface UpdateEventSourceMappingCommandOutput extends EventSourceMappingConfiguration {}

Event Source Mapping Retrieval

Returns details about an event source mapping.

class GetEventSourceMappingCommand {
  constructor(input: GetEventSourceMappingCommandInput);
}

interface GetEventSourceMappingCommandInput {
  /** The identifier of the event source mapping */
  UUID: string;
}

interface GetEventSourceMappingCommandOutput extends EventSourceMappingConfiguration {}

Event Source Mapping Listing

Returns a list of event source mappings you created using the CreateEventSourceMapping.

class ListEventSourceMappingsCommand {
  constructor(input: ListEventSourceMappingsCommandInput);
}

interface ListEventSourceMappingsCommandInput {
  /** The Amazon Resource Name (ARN) of the event source */
  EventSourceArn?: string;
  /** The name or ARN of the Lambda function */
  FunctionName?: string;
  /** A pagination token returned by a previous call */
  Marker?: string;
  /** The maximum number of event source mappings to return */
  MaxItems?: number;
}

interface ListEventSourceMappingsCommandOutput {
  /** A pagination token that's returned when the response doesn't contain all event source mappings */
  NextMarker?: string;
  /** A list of event source mappings */
  EventSourceMappings?: EventSourceMappingConfiguration[];
}

Event Source Mapping Deletion

Deletes an event source mapping. You can get the identifier of a mapping from the output of ListEventSourceMappings.

class DeleteEventSourceMappingCommand {
  constructor(input: DeleteEventSourceMappingCommandInput);
}

interface DeleteEventSourceMappingCommandInput {
  /** The identifier of the event source mapping */
  UUID: string;
}

interface DeleteEventSourceMappingCommandOutput extends EventSourceMappingConfiguration {}

Core Types

interface EventSourceMappingConfiguration {
  /** The identifier of the event source mapping */
  UUID?: string;
  /** The position in a stream from which to start reading */
  StartingPosition?: EventSourcePosition;
  /** With StartingPosition set to AT_TIMESTAMP, the time from which to start reading */
  StartingPositionTimestamp?: Date;
  /** The maximum number of records in each batch that Lambda pulls from your stream or queue */
  BatchSize?: number;
  /** The maximum amount of time, in seconds, that Lambda spends gathering records before invoking the function */
  MaximumBatchingWindowInSeconds?: number;
  /** The number of batches to process concurrently from each shard */
  ParallelizationFactor?: number;
  /** The Amazon Resource Name (ARN) of the event source */
  EventSourceArn?: string;
  /** The ARN of the Lambda function */
  FunctionArn?: string;
  /** The date that the event source mapping was last updated or that its state changed */
  LastModified?: Date;
  /** The result of the last Lambda invocation of your function */
  LastProcessingResult?: string;
  /** The state of the event source mapping */
  State?: string;
  /** Indicates whether a user or Lambda made the last change to the event source mapping */
  StateTransitionReason?: string;
  /** Configuration object that specifies the destination of an event after Lambda processes it */
  DestinationConfig?: DestinationConfig;
  /** The name of the Kafka topic */
  Topics?: string[];
  /** The name of the Amazon SQS queue */
  Queues?: string[];
  /** An array of the authentication protocol, VPC components, or virtual host to secure your event source */
  SourceAccessConfigurations?: SourceAccessConfiguration[];
  /** The self-managed Apache Kafka cluster for your event source */
  SelfManagedEventSource?: SelfManagedEventSource;
  /** Discard records older than the specified age */
  MaximumRecordAgeInSeconds?: number;
  /** If the function returns an error, split the batch in two and retry */
  BisectBatchOnFunctionError?: boolean;
  /** Discard records after the specified number of retries */
  MaximumRetryAttempts?: number;
  /** The duration in seconds of a processing window */
  TumblingWindowInSeconds?: number;
  /** A list of current response type enums applied to the event source mapping */
  FunctionResponseTypes?: FunctionResponseType[];
  /** Configuration settings for an Amazon Managed Streaming for Apache Kafka event source */
  AmazonManagedKafkaEventSourceConfig?: AmazonManagedKafkaEventSourceConfig;
  /** Configuration settings for a self-managed Apache Kafka event source */
  SelfManagedKafkaEventSourceConfig?: SelfManagedKafkaEventSourceConfig;
  /** The scaling configuration for the event source */
  ScalingConfig?: ScalingConfig;
  /** Configuration settings for a DocumentDB event source */
  DocumentDBEventSourceConfig?: DocumentDBEventSourceConfig;
  /** Criteria for filtering events from the event source */
  FilterCriteria?: FilterCriteria;
  /** The ARN of the Key Management Service (KMS) customer managed key used to encrypt the filter criteria */
  KMSKeyArn?: string;
  /** Represents an error object for filter criteria */
  FilterCriteriaError?: FilterCriteriaError;
  /** The Amazon Resource Name (ARN) of the event source mapping */
  EventSourceMappingArn?: string;
  /** Configuration for enabling metrics for an event source mapping */
  MetricsConfig?: EventSourceMappingMetricsConfig;
  /** Configuration for provisioned pollers used by an event source mapping */
  ProvisionedPollerConfig?: ProvisionedPollerConfig;
}

enum EventSourcePosition {
  /** Start reading from the latest record */
  LATEST = "LATEST",
  /** Start reading from the oldest record */
  TRIM_HORIZON = "TRIM_HORIZON",
  /** Start reading from a specified timestamp */
  AT_TIMESTAMP = "AT_TIMESTAMP"
}

interface SourceAccessConfiguration {
  /** The type of authentication protocol, VPC components, or virtual host for your event source */
  Type?: SourceAccessType;
  /** The value for your chosen configuration in Type */
  URI?: string;
}

enum SourceAccessType {
  BASIC_AUTH = "BASIC_AUTH",
  VPC_SUBNET = "VPC_SUBNET",
  VPC_SECURITY_GROUP = "VPC_SECURITY_GROUP",
  SASL_SCRAM_512_AUTH = "SASL_SCRAM_512_AUTH",
  SASL_SCRAM_256_AUTH = "SASL_SCRAM_256_AUTH",
  VIRTUAL_HOST = "VIRTUAL_HOST",
  CLIENT_CERTIFICATE_TLS_AUTH = "CLIENT_CERTIFICATE_TLS_AUTH",
  SERVER_ROOT_CA_CERTIFICATE = "SERVER_ROOT_CA_CERTIFICATE"
}

interface SelfManagedEventSource {
  /** The list of bootstrap servers for your Kafka brokers */
  Endpoints?: Record<string, string[]>;
}

enum FunctionResponseType {
  /** Report batch item failures to allow partial batch success */
  ReportBatchItemFailures = "ReportBatchItemFailures"
}

interface AmazonManagedKafkaEventSourceConfig {
  /** The identifier for the Kafka consumer group to join */
  ConsumerGroupId?: string;
}

interface SelfManagedKafkaEventSourceConfig {
  /** The identifier for the Kafka consumer group to join */
  ConsumerGroupId?: string;
}

interface ScalingConfig {
  /** Limits the number of concurrent instances that the Amazon SQS event source can invoke */
  MaximumConcurrency?: number;
}

interface DocumentDBEventSourceConfig {
  /** The name of the database to consume within the DocumentDB cluster */
  DatabaseName?: string;
  /** The name of the collection to consume within the database */
  CollectionName?: string;
  /** Determines what DocumentDB sends to your event stream during data changes */
  FullDocument?: FullDocument;
}

enum FullDocument {
  UpdateLookup = "UpdateLookup",
  Default = "Default"
}

interface DestinationConfig {
  /** The destination configuration for successful invocations */
  OnSuccess?: OnSuccess;
  /** The destination configuration for failed invocations */
  OnFailure?: OnFailure;
}

interface OnSuccess {
  /** The Amazon Resource Name (ARN) of the destination resource */
  Destination?: string;
}

interface OnFailure {
  /** The Amazon Resource Name (ARN) of the destination resource */
  Destination?: string;
}

Common Event Source Patterns

Amazon Kinesis Data Streams

const kinesisEventSource = new CreateEventSourceMappingCommand({
  EventSourceArn: "arn:aws:kinesis:region:account:stream/stream-name",
  FunctionName: "my-function",
  StartingPosition: "LATEST",
  BatchSize: 100,
  MaximumBatchingWindowInSeconds: 5,
  ParallelizationFactor: 1,
  MaximumRecordAgeInSeconds: 300,
  BisectBatchOnFunctionError: true,
  MaximumRetryAttempts: 3,
  DestinationConfig: {
    OnFailure: {
      Destination: "arn:aws:sqs:region:account:dlq-name"
    }
  }
});

Amazon DynamoDB Streams

const dynamoEventSource = new CreateEventSourceMappingCommand({
  EventSourceArn: "arn:aws:dynamodb:region:account:table/table-name/stream/timestamp",
  FunctionName: "my-function",
  StartingPosition: "TRIM_HORIZON",
  BatchSize: 10,
  MaximumBatchingWindowInSeconds: 1,
  ParallelizationFactor: 2,
  BisectBatchOnFunctionError: true,
  MaximumRetryAttempts: 2
});

Amazon SQS

const sqsEventSource = new CreateEventSourceMappingCommand({
  EventSourceArn: "arn:aws:sqs:region:account:queue-name",
  FunctionName: "my-function",
  BatchSize: 10,
  MaximumBatchingWindowInSeconds: 5,
  FunctionResponseTypes: ["ReportBatchItemFailures"],
  ScalingConfig: {
    MaximumConcurrency: 100
  }
});

Amazon MSK (Managed Streaming for Apache Kafka)

const mskEventSource = new CreateEventSourceMappingCommand({
  EventSourceArn: "arn:aws:kafka:region:account:cluster/cluster-name/cluster-uuid",
  FunctionName: "my-function",
  Topics: ["topic1", "topic2"],
  BatchSize: 100,
  MaximumBatchingWindowInSeconds: 5,
  StartingPosition: "LATEST",
  AmazonManagedKafkaEventSourceConfig: {
    ConsumerGroupId: "my-consumer-group"
  }
});

Additional Interfaces

interface FilterCriteria {
  /** A list of filters to be applied to the event stream */
  Filters?: Filter[];
}

interface Filter {
  /** The filter pattern */
  Pattern?: string;
}

interface FilterCriteriaError {
  /** The error code */
  ErrorCode?: string;
  /** The error message */
  Message?: string;
}

interface EventSourceMappingMetricsConfig {
  /** Configuration settings for metrics for an event source mapping */
  Metrics?: EventSourceMappingMetrics[];
}

enum EventSourceMappingMetrics {
  EventCount = "EventCount"
}

interface ProvisionedPollerConfig {
  /** The minimum number of workers */
  MinimumPollers?: number;
  /** The maximum number of workers */
  MaximumPollers?: number;
}