简体   繁体   中英

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

}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM