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?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠