constructor()

in source/lib/event-stack.ts [36:99]


    constructor(scope: Construct, id: string, props: EventProps) {
        super(scope, id);

        // Enable S3 Notification
        props.queue.addToResourcePolicy(new iam.PolicyStatement({
            actions: ['SQS:SendMessage'],
            effect: iam.Effect.ALLOW,
            resources: [props.queue.queueArn],
            principals: [new iam.ServicePrincipal('s3.amazonaws.com')],
            conditions: {
                StringEquals: {
                    "aws:SourceArn": props.bucket.bucketArn,
                }
            }
        }))


        const hasDelete = new CfnCondition(this, 'hasDelete', {
            expression: Fn.conditionEquals('CreateAndDelete', props.events),
        });
        const events = Fn.conditionIf(hasDelete.logicalId, 's3:ObjectCreated:*,s3:ObjectRemoved:Delete', 's3:ObjectCreated:*').toString();



        const s3Notification = new cr.AwsCustomResource(this, 'S3NotificationTrigger', {
            resourceType: 'Custom::CustomResource',
            policy: cr.AwsCustomResourcePolicy.fromStatements([
                new iam.PolicyStatement({
                    actions: ["S3:PutBucketNotification", "S3:GetBucketNotification"],
                    resources: [props.bucket.bucketArn],
                }),
            ]),
            timeout: Duration.minutes(15),
            onCreate: {
                service: 'S3',
                action: 'putBucketNotificationConfiguration',
                parameters: {
                    Bucket: props.bucket.bucketName,
                    NotificationConfiguration: {
                        QueueConfigurations: [
                            {
                                Events: Fn.split(',', events),
                                QueueArn: props.queue.queueArn,
                                Id: `${props.queue.queueName}-DTH-Notification`,
                                Filter: {
                                    Key: {
                                        FilterRules: [
                                            {
                                                Name: 'prefix',
                                                Value: props.prefix,
                                            }
                                        ]
                                    }
                                }
                            }
                        ]
                    },

                },
                physicalResourceId: cr.PhysicalResourceId.of(Date.now().toString())
            },
        });
        s3Notification.node.addDependency(props.queue)
    }