'how to create an s3 bucket and objects with no public access in AWS using sdk go
How to make this s3 bucket private so that all objects are also private by default ?
func CreateBucket(svc *s3.S3, bucketName string) error {
fmt.Printf("\n=====================================================\n")
fmt.Printf("\nCreating a new bucket named '" + bucketName + "'...\n\n")
_, err := svc.CreateBucket(&s3.CreateBucketInput{
Bucket: aws.String(bucketName),
//ACL: ACLPrivateRead,
})
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "409" {
return nil
}
}
return err
}
return nil
}
Solution 1:[1]
From official Go SDK documentation, you can use PublicAccessBlockRequest to check if the bucket allows Public Access. This Block Request works in a way that it should be True / enabled to block public access. There are methods to Get, Put, Delete this config from bucket.
Reference to documentation with functions https://docs.aws.amazon.com/sdk-for-go/api/service/s3/#S3.CreateBucket
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hussain Mansoor |
