Skip to content
v2.273.0

SqsEventSource Class ​

Use an Amazon SQS queue as an event source for AWS Lambda.

Example ​

ts
import * as eventsources from 'aws-cdk-lib/aws-lambda-event-sources';
import * as sqs from 'aws-cdk-lib/aws-sqs';

declare const fn: lambda.Function;
const queue = new sqs.Queue(this, 'Queue');
fn.addEventSource(new eventsources.SqsEventSource(queue));
python
import aws_cdk.aws_lambda_event_sources as eventsources
import aws_cdk.aws_sqs as sqs

# fn: lambda.Function

queue = sqs.Queue(self, "Queue")
fn.add_event_source(eventsources.SqsEventSource(queue))
java
import software.amazon.awscdk.services.lambda.eventsources.*;
import software.amazon.awscdk.services.sqs.*;

Function fn;

Queue queue = new Queue(this, "Queue");
fn.addEventSource(new SqsEventSource(queue));
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.Lambda.EventSources;
using Amazon.CDK.AWS.SQS;

Function fn;

var queue = new Queue(this, "Queue");
fn.AddEventSource(new SqsEventSource(queue));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import eventsources "github.com/aws/aws-cdk-go/awscdk"
import sqs "github.com/aws/aws-cdk-go/awscdk"

var fn Function

queue := sqs.NewQueue(this, jsii.String("Queue"))
fn.AddEventSource(eventsources.NewSqsEventSource(queue))

Initializer ​

ts
new SqsEventSource(queue: IQueue, props?: SqsEventSourceProps)
python
SqsEventSource(queue: IQueue, props: typing.Optional[SqsEventSourceProps] = None)
java
new SqsEventSource(IQueue queue, SqsEventSourceProps props)
csharp
new SqsEventSource(IQueue queue, SqsEventSourceProps? props = null)
go
NewSqsEventSource(Queue IQueue, Props SqsEventSourceProps)

Properties ​

eventSourceMappingArnstringevent_source_mapping_arnstreventSourceMappingArnStringEventSourceMappingArnstringEventSourceMappingArn*stringrequired#
The ARN for this EventSourceMapping.
eventSourceMappingIdstringevent_source_mapping_idstreventSourceMappingIdStringEventSourceMappingIdstringEventSourceMappingId*stringrequired#
The identifier for this EventSourceMapping.
queueIQueuequeueIQueuequeueIQueueQueueIQueueQueueIQueuerequired#

Methods ​

bind(target: IFunction): voiddef bind(self, target: IFunction) -> Nonepublic void bind(IFunction target)public void Bind(IFunction target)func Bind(Target IFunction)#
Called by `lambda.addEventSource` to allow the event source to bind to this function.