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 個回答
0
已接受的答案

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
已回答 2 年前
  • 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?

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南