How to add S3 BucketPolicy with AWS CDK

0 votes

I wanna translate this CloudFormation piece into CDK:

Type: AWS::S3::BucketPolicy
Properties:
  Bucket:
    Ref: S3BucketImageUploadBuffer
  PolicyDocument:
    Version: "2012-10-17"
    Statement:
      Action:
        - s3:PutObject
        - s3:PutObjectAcl
      Effect: Allow
      Resource:
        - ...

Mar 8, 2022 in Others by Edureka
• 13,690 points
3,206 views

1 answer to this question.

0 votes
In AWS CDK, there are two ways to build a bucket policy:

utilise the addToResourcePolicy function on a Bucket class object.
Create an instance of the BucketPolicy class.
With the addToResourcePolicy method, we take an implicit approach: once we add a policy statement to the bucket, CDK constructs a bucket policy for us.

The second technique is explicit and a little easier to understand for the reader of our code.

This article's code may be found on GitHub.
Let's take a look at a real-life example of both. First, let's look at the addToResourcePolicy method:

lib/cdk-starter-s
answered Mar 9, 2022 by gaurav
• 23,260 points

Related Questions In Others

0 votes
0 answers

How to import existing VPC in aws cdk?

Hi I am working on aws cdk. ...READ MORE

Mar 9, 2022 in Others by Edureka
• 13,690 points
955 views
0 votes
1 answer

NodeJS Amazon AWS S3 getObject how to send file in API response to download

Server Side const aws = require('aws-sdk'); router.get('/getfilefroms3', async (req, ...READ MORE

answered Mar 24, 2022 in Others by gaurav
• 23,260 points
9,646 views
0 votes
1 answer

How to automate AWS Elastic Transcoder Jobs for s3 buckets?

This article will walk you through uploading ...READ MORE

answered Mar 24, 2022 in Others by gaurav
• 23,260 points
817 views
0 votes
1 answer

How to add Header and Footer in excel with vb.net?

This code will work: Imports Microsoft.Office.Interop Private Sub Button1_Click(sender ...READ MORE

answered Dec 10, 2022 in Others by narikkadan
• 63,720 points
710 views
0 votes
1 answer

How to communicate gRPC example working with Node.js?

hi.. you can read below link, it ...READ MORE

answered Dec 2, 2019 in Others by Narendra Reddy Dalli
2,289 views
0 votes
1 answer
+1 vote
0 answers

How to split a number with coma betweeen two colunms

Jul 3, 2019 in Others by anonymous
762 views
0 votes
0 answers

How to add S3 BucketPolicy with AWS CDK?

I wanna translate this CloudFormation piece into ...READ MORE

Mar 11, 2022 in Others by Edureka
• 13,690 points
1,079 views
0 votes
1 answer

How to install a GUI on Amazon AWS EC2 or EMR with the Amazon AMI

The top-level script for installing the GUI ...READ MORE

answered Mar 9, 2022 in Others by gaurav
• 23,260 points
921 views
0 votes
1 answer

How to use AWS S3 CLI to dump files to stdout in BASH?

All file objects must have their contents ...READ MORE

answered Mar 24, 2022 in Others by gaurav
• 23,260 points
2,081 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP