1. Answers
  2. Creating an AWS S3 Bucket Public Access Block

How do I create an AWS S3 bucket public access block?

This example demonstrates how to create an AWS S3 bucket with public access block settings to ensure the contents of the bucket remain private. The program sets up the bucket and applies the public access block configuration.

Below is the complete program that accomplishes this task:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const exampleBucket = new aws.s3.BucketV2("example_bucket", {
    bucket: "my-example-public-access-block-bucket",
    tags: {
        Name: "ExampleBucket",
        Environment: "Dev",
    },
});
const exampleBucketPublicAccessBlock = new aws.s3.BucketPublicAccessBlock("example_bucket_public_access_block", {
    bucket: exampleBucket.bucket,
    blockPublicAcls: true,
    blockPublicPolicy: true,
    ignorePublicAcls: true,
    restrictPublicBuckets: true,
});
export const bucketId = exampleBucket.id;
export const publicAccessBlockId = exampleBucketPublicAccessBlock.id;

Key Points

  • AWS S3 Bucket: Created to store objects and data.
  • Public Access Block Configuration: Ensures the contents of the bucket are private by blocking public access.
  • Outputs: Provides the bucket ID and public access block ID for reference.

Summary

This program creates an AWS S3 bucket and configures its public access block settings, ensuring the bucket contents remain private by preventing public access through various block settings.

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