Lambda Event Sources need to create a dependency to the OnFailure resource
See original GitHub issueWithout 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:
- Created 3 years ago
- Comments:12 (12 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see. Yes, it’s semantically correct to have it defined, nevertheless.
Closing this issue for now since there hasn’t been a response in a while. Feel free to reopen.