I'm running into a cyclic issue with this
props.incomingBucket.addEventNotification(EventType.OBJECT_CREATED, new s3notifications.LambdaDestination(this.incomingHandler));
This is the error I get:
throw new Error(
'${target.node.path}' depends on '${this.node.path}' (${cycle.join(', ')}). Adding this dependency (${reason}) would create a cyclic reference.);
I have incomingBucket in stack A, and incomingHandler in stackB, this props.incomingBucket.addEventNotification(EventType.OBJECT_CREATED, new s3notifications.LambdaDestination(this.incomingHandler)); is in stackB but it’s running into this issue. However, props.incomingBucket.grantReadWrite(this.incomingHandler); this has no issues, so I’m not entirely sure what’s going on…
This is my full stack:
export interface LambdaProps {
readonly env: DeploymentEnvironment;
readonly stackName?: string;
readonly stage: string;
readonly vpc: EC2Vpc;
readonly incomingBucket: Bucket;
readonly blobsBucket: Bucket;
readonly blobsTable: Table;
readonly identExtractor: Extractor;
}
export class LambdaStack extends DeploymentStack {
public readonly apiLambda: IFunction;
public readonly dropboxLambda: IFunction;
public readonly incomingHandler: IFunction;
constructor(parent: core.App, name: string, props: LambdaProps) {
super(parent, name, {
softwareType: SoftwareType.INFRASTRUCTURE,
...props
});
this.incomingHandler = new Function(this, "IncomingHandler", {
code: .... stuff here,
handler: 'handlers.incoming_lambda',
runtime: Runtime.PYTHON_3_7,
timeout: core.Duration.seconds(30),
environment: {
.... stuff here
}
});
// // new blobs in the incoming bucket trigger lambda event
// TODO ok this is causing a circular issue, need to figure out how to fix
props.incomingBucket.addEventNotification(EventType.OBJECT_CREATED, new s3notifications.LambdaDestination(this.incomingHandler));
// grant permissions to the incoming lambda.
props.incomingBucket.grantReadWrite(this.incomingHandler);
props.blobsBucket.grantReadWrite(this.incomingHandler);
props.blobsTable.grantReadWriteData(this.incomingHandler);
props.identExtractor.taskQueue.grantSendMessages(this.incomingHandler);
}
}