I am looking to set up an S3 bucket in one stack, pass it to another stack, and then utilize it for creating a notification in either an SNS or SQS. Below is an example of what the code breakdown would resemble.
Stack 1
export class BucketStack extends BaseStack {
public readonly mynBucket: Bucket;
constructor(scope: App, id: string, props?: StackProps) {
const properties: StackProps = {
env: {
region: StackConfiguration.region,
},
};
super(scope, id, properties);
this.myBucket = this.createMyBucket();
}
private createMyBucket() {
// create and return bucket
}
Stack 2
import * as s3n from '@aws-cdk/aws-s3-notifications';
export class ServiceStack extends BaseStack {
constructor(scope: App, id: string, myBucket: Bucket) {
const properties: StackProps = {
env: {
region: StackConfiguration.region,
},
};
super(scope, id, properties);
const topic = new Topic(this, 'Topic');
myBucket.addEventNotification(EventType.OBJECT_CREATED_PUT, new s3n.SnsDestination(topic));
An error has occurred:
Error: 'my-bucket-stack' depends on 'my-service-stack' (Depends on Lambda resources., Depends on resources.). Adding this dependency (my-service-stack -> my-bucket-stack/myBucket/Resource.Arn) would create a cyclic reference.