question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lambda Event Sources need to create a dependency to the OnFailure resource

See original GitHub issue

Without the dependsOn being generated in the CFT the EventSource can be generated with an empty OnFailure destination.

Reproduction Steps

import cdk = require('@aws-cdk/core');
import dynamodb = require('@aws-cdk/aws-dynamodb');
import eventSource = require('@aws-cdk/aws-lambda-event-sources');
import lambda = require('@aws-cdk/aws-lambda');
import sqs = require('@aws-cdk/aws-sqs');
import {Construct} from "@aws-cdk/core";

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

    const table = new dynamodb.Table(this, 'table', {
      partitionKey: {
        name: 'pk',
        type: dynamodb.AttributeType.STRING
      },
      stream: dynamodb.StreamViewType.NEW_IMAGE
    });

    const testlambda = new lambda.Function(this, 'TestFunction', {
      code: lambda.Code.fromInline('handler = () => console.log("handled");'),
      runtime: lambda.Runtime.NODEJS_12_X,
      handler: 'index.handler',
      description: 'Example function',
    });

    const sqsQueue = new sqs.Queue(this, 'sqsDLQ', {
    });

    testlambda.addEventSource(
        new eventSource.DynamoEventSource(table, {
          startingPosition: lambda.StartingPosition.TRIM_HORIZON,
          batchSize: 1,
          retryAttempts: 0,
          onFailure: new eventSource.SqsDlq(sqsQueue)
        })
    );
  }
}

Error Log

Environment

  • **CLI Version : >1.29.0 **
  • Framework Version:
  • OS :
  • Language :

Other

Register dependency on the DLQ with the EventSource when it is created.

Hack work around (added to stack):

    let dynamoDBEventSource = {} as Construct;

    for (let i = 0; i < testlambda.node.children.length; i++) {
        if (testlambda.node.children[i].node.uniqueId.includes('DynamoDBEventSource')) {
            dynamoDBEventSource = testlambda.node.children[i] as Construct;
        }
    }

    dynamoDBEventSource.node.addDependency(sqsQueue);

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
nija-atcommented, Mar 27, 2020

I see. Yes, it’s semantically correct to have it defined, nevertheless.

0reactions
SomayaBcommented, May 4, 2020

Closing this issue for now since there hasn’t been a response in a while. Feel free to reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/aws-lambda-event-sources module
This module includes classes that allow using various AWS services as event sources for AWS Lambda via the high-level lambda.addEventSource(source) API. NOTE: ...
Read more >
terraform-aws-modules/lambda/aws
Build dependencies for your Lambda Function and Layer. ... tracing, async events, event source mapping, IAM role, IAM policies, and more).
Read more >
@aws-cdk/aws-lambda-event-sources - Package Manager
An event source mapping is an AWS Lambda resource that reads from an event source and invokes a Lambda function. You can use...
Read more >
13 AWS Lambda design considerations you need to know about
As with all AWS services, the principle of least privilege should be applied to the IAM Roles of Lambda functions. When creating IAM...
Read more >
AWS Lambda | AWS Cheat Sheet - Digital Cloud Training
You specify the amount of memory you need allocated to your Lambda functions. ... An event source is an AWS service or developer-created...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found