AWS CloudFormation
User Guide (API Version 2010-05-15)

AWS::Lambda::EventSourceMapping

The AWS::Lambda::EventSourceMapping resource creates a mapping between an event source and an AWS Lambda function. Lambda reads items from the event source and triggers the function. For more information, see AWS Lambda Event Source Mapping in the AWS Lambda Developer Guide.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

{ "Type" : "AWS::Lambda::EventSourceMapping", "Properties" : { "BatchSize" : Integer, "Enabled" : Boolean, "EventSourceArn" : String, "FunctionName" : String, "StartingPosition" : String } }

YAML

Type: AWS::Lambda::EventSourceMapping Properties: BatchSize: Integer Enabled: Boolean EventSourceArn: String FunctionName: String StartingPosition: String

Properties

BatchSize

The maximum number of items to retrieve in a single batch.

  • Amazon Kinesis – Default 100. Max 10,000.

  • Amazon DynamoDB Streams – Default 100. Max 1,000.

  • Amazon Simple Queue Service – Default 10. Max 10.

Required: No

Type: Integer

Update requires: No interruption

Enabled

Set to false to pause polling and invocation.

Required: No

Type: Boolean

Update requires: No interruption

EventSourceArn

The Amazon Resource Name (ARN) of the event source.

  • Amazon Kinesis – The ARN of the data stream or a stream consumer.

  • Amazon DynamoDB Streams – The ARN of the stream.

  • Amazon Simple Queue Service – The ARN of the queue.

Required: Yes

Type: String

Update requires: Replacement

FunctionName

The name of the Lambda function.

Name formats

  • Function name - MyFunction.

  • Function ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction.

  • Version or Alias ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction:PROD.

  • Partial ARN - 123456789012:function:MyFunction.

Required: Yes

Type: String

Update requires: No interruption

StartingPosition

The position in a stream from which to start reading. Required for Amazon Kinesis and Amazon DynamoDB Streams sources. AT_TIMESTAMP is only supported for Kinesis streams.

Valid Values: TRIM_HORIZON | LATEST | AT_TIMESTAMP

Required: No

Type: String

Update requires: Replacement

Return Values

Ref

When the logical ID of this resource is provided to the Ref intrinsic function, Ref returns the resource name.

For more information about using the Ref function, see Ref.

Example

The following example associates an Kinesis stream with a Lambda function.

JSON

"EventSourceMapping": { "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "EventSourceArn" : { "Fn::Join" : [ "", [ "arn:aws:kinesis:", { "Ref" : "AWS::Region" }, ":", { "Ref" : "AWS::AccountId" }, ":stream/", { "Ref" : "KinesisStream" }] ] }, "FunctionName" : { "Fn::GetAtt" : ["LambdaFunction", "Arn"] }, "StartingPosition" : "TRIM_HORIZON" } }

YAML

EventSourceMapping: Type: AWS::Lambda::EventSourceMapping Properties: EventSourceArn: Fn::Join: - "" - - "arn:aws:kinesis:" - Ref: "AWS::Region" - ":" - Ref: "AWS::AccountId" - ":stream/" - Ref: "KinesisStream" FunctionName: Fn::GetAtt: - "LambdaFunction" - "Arn" StartingPosition: "TRIM_HORIZON"