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?

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ