Skip to content

Latest commit

 

History

History
100 lines (75 loc) · 2.98 KB

s3.md

File metadata and controls

100 lines (75 loc) · 2.98 KB
title cloud service description library brand og
How to create an AWS S3 bucket with Pulumi
AWS
S3
is object storage built to store and retrieve any amount of data from anywhere
@pulumi/aws
aws
description image
Use Pulumi to code, deploy, and manage cloud, serverless, and container apps and infrastructure
/images/service/aws-sw3.png

This reference shows how to use Pulumi to define an {{ page.cloud }} {{ page.service }} resource using pure code which can then be deployed to {{ page.cloud }} and managed as infrastructure as code.

What is {{ page.cloud }} {{ page.service }}?

{{ page.brand }}

{{ page.cloud }} {{ page.service }} {{ page.description }}. Find out more at AWS here.

Create an {{ page.cloud }} {{ page.service }} resource using {{ page.library }}

The {{ page.library }} library enables fine-grained control over the {{ page.cloud }} {{ page.service }} resource meaning it can be coded, deployed, and managed entirely in code.

const aws = require("@pulumi/aws");

const bucket = new aws.s3.Bucket("my-bucket");

const bucketMetric = new aws.s3.BucketMetric("my-bucket-metric", {
    bucket: bucket.bucket
});

const bucketNotification = new aws.s3.BucketNotification("my-bucket-notification", {
    bucket: bucket.bucket
});

const bucketObject = new aws.s3.BucketObject("my-bucket-object", {
    bucket: bucket.bucket,
    content: "hello world"
});

const bucketPolicy = new aws.s3.BucketPolicy("my-bucket-policy", {
    bucket: bucket.bucket,
    policy: bucket.bucket.apply(publicReadPolicyForBucket)
})

function publicReadPolicyForBucket(bucketName: string) {
    return JSON.stringify({
        Version: "2012-10-17",
        Statement: [{
            Effect: "Allow",
            Principal: "*",
            Action: [
                "s3:GetObject"
            ],
            Resource: [
                `arn:aws:s3:::${bucketName}/*` // policy refers to bucket name explicitly
            ]
        }]
    });
}

Create an {{ page.cloud }} {{ page.service }} bucket using @pulumi/cloud

The @pulumi/cloud library provides a high-level abstraction over the {{ page.cloud }} {{ page.service }} resource ensuring the same code can be used in multi-cloud environments.

const cloud = require("@pulumi/cloud-aws");
const aws = require("@pulumi/aws");

// A new bucket that will work in any cloud
const bucket = new cloud.Bucket("bucket");