I am creating a webhook API and then passing the URL to a s3 Notification lambda but it creates a cyclic reference and I am not sure what is the problem and what should be an ideal solution.
Error
Error: 'webhookStack' depends on 's3EventStack' (webhookStack -> s3Stack/hls-audio-dist/Resource.DomainName, s3Stack -> s3EventStack/audio-bucket-event-handler/Resource.Arn). Adding this dependency (s3EventStack -> webhookStack/coconut-webhook-api/Resource.Ref) would create a cyclic reference.
at S3EventStack._addAssemblyDependency
WebhookStack
const webhookLambda = createLambdaHandler<WebhookLambdaProps>(
this,
"coconut-webhook",
{
path: "webhook/coconut-webhook",
env: {
cloudfrontURL: "holycow",
wsDBTableName: wsDbTable.tableName,
wsURL: wsStage.url,
webhookSecret: webhookSecret,
},
}
);
this.webhookLambda = webhookLambda;
webSocketApi.grantManageConnections(webhookLambda);
const api = new LambdaRestApi(this, "coconut-webhook-api", {
description: "webhook for coconut processing",
proxy: false,
deployOptions: {
stageName: "dev",
},
handler: webhookLambda,
});
// set the webhook url to be used in s3
// https://url.amz.com/notify?secret=123
this.webhookURL = `${api.url}notify`;
Everything stays fine until I use the env in lambda
s3EventStack
const bucketListenerLambda = createLambdaHandler<BucketUploadEventEnvProps>(
this,
"audio-bucket-event-handler",
{
path: "events/bucket-event",
env: {
// when passed it gives error
webhookURL: props.webhookURL
},
}
);
// add listener on the bucket
rawAudioBucket.addEventNotification(
s3.EventType.OBJECT_CREATED,
new s3n.LambdaDestination(bucketListenerLambda)
);
wsDbTable.grantWriteData(bucketListenerLambda);
stack
const cocoWebhook = new WebhookStack(app, "webhookStack", {
wsDbTable,
});
const s3Stack = new S3Stack(app, "s3Stack", {
wsDbTable,
webhookLambda: cocoWebhook.webhookLambda,
bucketNames: S3_BUCKET_NAMES,
});
const s3EventStack = new S3EventStack(app, "s3EventStack", {
wsDbTable,
webhookLambda: cocoWebhook.webhookLambda,
webhookURL: cocoWebhook.webhookURL,
rawAudioBucket: s3Stack.rawAudioBucket,
});
I am not an expert in this field, if anyone could explain whats going on here, it would be a great help.
Current workaround
- Use SSM parameter store