1. Answers
  2. Creating an S3 Bucket with ACLs in TypeScript

How do I create an S3 Bucket with ACLs in TypeScript?

In this guide, we will create an S3 bucket using Pulumi in TypeScript and apply Access Control Lists (ACLs) to it. ACLs are a way to manage access permissions for the bucket and its objects.

Key Points

  • Create an S3 bucket using aws.s3.BucketV2.
  • Apply ACLs to manage access permissions.
  • Define the bucket and ACLs in the entire example.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create an S3 bucket
const bucket = new aws.s3.BucketV2("my-bucket", {
    bucket: "my-example-bucket",
    acl: "private", // Set the ACL to private
});

// Define ACLs for the bucket
const bucketAcl = new aws.s3.BucketAclV2("my-bucket-acl", {
    bucket: bucket.bucket,
    accessControlPolicy: {
        grants: [
            {
                grantee: {
                    type: "CanonicalUser",
                    id: "your-canonical-user-id",
                },
                permission: "FULL_CONTROL",
            },
            {
                grantee: {
                    type: "Group",
                    uri: "http://acs.amazonaws.com/groups/global/AllUsers",
                },
                permission: "READ",
            },
        ],
        owner: {
            id: "your-canonical-user-id",
        },
    },
});

// Export the bucket name
export const bucketName = bucket.bucket;

Summary

In this guide, we created an S3 bucket and applied ACLs to it using Pulumi in TypeScript. We defined a bucket with a private ACL and configured additional ACLs to grant full control to a specific user and read access to all users. This setup helps manage access permissions effectively for the bucket and its objects.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up