enable Amazon EventBridge for s3 bucket via CDK

0

Hi team,

I create a bucket with CDK and set the property eventBridgeEnabled to true

const bucket = new Bucket(
      this,
      "myBucket",
      {
        versioned: false,
        publicReadAccess: false,
        blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
     **eventBridgeEnabled: true**,
      }
    );

but when I go to the** s3 console** and check the properties tab/ EventBridge it's still showing "off" instead of "on"

is there anything missing?

Thank you.

  • I just created a cdk project using 2.21.1 and it worked. Send notifications to Amazon EventBridge for all events in this bucket On

    What version are you using?

  • I'm using version 1.153.1

1 Answer
0
Accepted Answer

Need to post answer to get the code formatting. Even with v1.153.1

npx cdk@1.153.1 init app --lanaguage typescript
npm install @aws-cdk/aws-s3
npm install @aws-cdk/aws-s3-deployment

Create a file to upload

mkdir web-dist
echo "Hello World" > ./web-dist/index.html

Go to ./lib/<name of the cdk project>.ts

import * as cdk from '@aws-cdk/core';
// import * as sqs from '@aws-cdk/aws-sqs';
import { Bucket, BlockPublicAccess } from '@aws-cdk/aws-s3';
import { BucketDeployment, Source } from '@aws-cdk/aws-s3-deployment';

export class RepostTemp2Stack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    const bucket = new Bucket(
      this,
      "myBucket",
      {
        versioned: false,
        publicReadAccess: false,
        blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
        eventBridgeEnabled: true,
      }
    );

    new BucketDeployment(this, 'DeployIndex', {
      destinationBucket: bucket,
      sources: [Source.asset('./web-dist')],
    });
  }
}

Now you can deploy the cdk project.

npx cdk deploy

Going to the deployed bucket and checking the properties shows:

Send notifications to Amazon EventBridge for all events in this bucket On

Maybe you have something else that is undoing the setting? Would need to see more of the app to understand what is going on.

AWS
answered 2 years ago
  • I'm using this package with my code : @aws-cdk/aws-s3-deployment

  • Updated to include s3-deployment. Did my answer solve your problem or are you still having trouble?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions