Skip to content

Lambda EventSourceMapping Failure Destination

Level: Error

Initial version: 0.1.6

cfn-lint: ES1001

tflint: aws_lambda_event_source_mapping_failure_destination

An AWS Lambda event source mapping reads from streams and poll-based event sources to invoke your functions. You can configure the event source mapping to send invocation records to another service such as Amazon SNS or Amazon SQS when it discards an event batch.

Implementations

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import { EventSourceMapping, SqsDlq, StartingPosition } from '@aws-cdk/aws-lambda';

export class MyStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new EventSourceMapping(scope, "MyEventSourceMapping", {
      target: myFunction,
      eventSourceArn: 'arn:aws:dynamodb:us-east-1:111122223333:table/my-table/stream/my-stream',
      startingPosition: StartingPosition.LATEST,
      onFailure: SqsDlq(mySqsQueue),
    });
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
{
  "Resource": {
    "MyEventSourceMapping": {
      "Type": "AWS::Lambda::EventSourceMapping",
      "Properties": {
        // Required properties
        "FunctionName": "my-function",
        "EventSourceArn": "arn:aws:dynamodb:us-east-1:111122223333:table/my-table/stream/my-stream",
        "StartingPosition": "LATEST",

        // Add an OnFailure destination on the event source mapping
        "DestinationConfig": {
          "OnFailure": {
            "Destination": "arn:aws:sqs:us-east-1:111122223333:my-dlq"
          }
        }
      }
    }
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Resources:
  MyEventSourceMapping:
    Type: AWS::Lambda::EventSourceMapping
    Properties:
      # Required properties
      FunctionName: my-function
      EventSourceArn: arn:aws:dynamodb:us-east-1:111122223333:table/my-table/stream/my-stream
      StartingPosition: LATEST

      # Add an OnFailure destination on the event source mapping
      DestinationConfig:
        OnFailure:
          Destination: arn:aws:sqs:us-east-1:111122223333:my-dlq 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
functions:
  MyFunction:
    handler: hello.handler

resources:
  Resources:
    MyEventSourceMapping:
      Type: AWS::Lambda::EventSourceMapping
      Properties:
        # Required properties
        FunctionName:
          Fn::Ref: MyFunction
        EventSourceArn: arn:aws:dynamodb:us-east-1:111122223333:table/my-table/stream/my-stream
        StartingPosition: LATEST

        # Add an OnFailure destination on the event source mapping
        DestinationConfig:
          OnFailure:
            Destination: arn:aws:sqs:us-east-1:111122223333:my-dlq 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
resource "aws_lambda_event_source_mapping" "this" {
  # Required fields
  event_source_arn  = "arn:aws:dynamodb:us-east-1:111122223333:table/my-table/stream/my-stream"
  function_name     = "my-function"
  starting_position = "LATEST"

  # Add an OnFailure destination on the event source mapping
  destination_config {
    on_failure {
      destination_arn = "arn:aws:sqs:us-east-1:111122223333:my-dlq"
    }
  }
}

See also