Pulumi - S3 Buckets
Table of Contents
Resources
Creating Buckets
Creating a bucket:
import * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws';
const bucket = new aws.s3.Bucket('BUCKET_NAME');
// export bucket id for later reference
export const bucketName = bucket.id;
Creating a bucket with options:
import * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws';
const bucket = new aws.s3.Bucket('BUCKET_NAME', {
website: {
indexDocument: 'index.html',
},
});
// export bucket id for later reference
export const bucketName = bucket.id;
Bucket Policies
To make the contents of a bucket public use the following:
const ownershipControls = new aws.s3.BucketOwnershipControls(
'ownership-controls',
{
bucket: bucket.id,
rule: {
objectOwnership: 'ObjectWriter',
},
},
);
const publicAccessBlock = new aws.s3.BucketPublicAccessBlock(
'public-access-block',
{
bucket: bucket.id,
blockPublicAcls: false,
},
);
Bucket Endpoint
If the bucket is configured as a website you can get the endpoint like this:
export const bucketEndpoint = pulumi.interpolate`http://${bucket.websiteEndpoint}`;