Come join Pulumi for the industry's first Cloud Engineering Summit! October 7–8. Save Your Spot

Modify the Program

Now that your S3 bucket is provisioned, let’s add an object to it. First, create a new directory called site.

$ mkdir site

Next create an index.html file you will upload to your bucket.

$ touch site/index.html
$ touch site/index.html
$ type nul > site/index.html

Once you’ve created your index.html file, add some content to it:

<html>
    <body>
        <h1>Hello, Pulumi!</h1>
    </body>
</html>

Now that you have your new index.html with some content, modify your program to add the contents of your index.html file to your S3 bucket. To accomplish this, we will take advantage of your chosen programming language’s native libraries to read the content of the file and assign it as an input to a new BucketObject.

const fs = require("fs");

Next you will create a new bucket object on the lines right after creating the bucket itself.

const bucketObject = new aws.s3.BucketObject("index.html", {
    bucket: bucket,
    content: fs.readFileSync("site/index.html").toString(),
});
import * as fs from "fs";

Next you will create a new bucket object on the lines right after creating the bucket itself.

const bucketObject = new aws.s3.BucketObject("index.html", {
    bucket: bucket,
    content: fs.readFileSync("site/index.html").toString(),
});

Next you will create a new bucket object on the lines right after creating the bucket itself.

bucketObject = s3.BucketObject(
    'index.html',
    bucket=bucket,
    content=open('site/index.html').read(),
)
import (
    "io/ioutil"
    // Existing imports...
)

Next you will create a new bucket object on the lines right after creating the bucket itself.

htmlContent, err := ioutil.ReadFile("site/index.html")
if err != nil {
    return err
}

_, err = s3.NewBucketObject(ctx, "index.html", &s3.BucketObjectArgs{
    Bucket:  bucket.ID(),
    Content: pulumi.String(string(htmlContent)),
})
if err != nil {
    return err
}
using System.IO;

Next you will create a new bucket object on the lines right after creating the bucket itself.

var filePath = Path.GetFullPath("./site/index.html");
var hmtlString = File.ReadAllText(filePath);

var bucketObject = new BucketObject("index.html", new BucketObjectArgs
{
    Bucket = bucket.BucketName,
    Content = hmtlString,
});

Notice how you provide the bucket you created earlier as an input to your new BucketObject. This is so Pulumi knows what S3 bucket the object should live in.

Next, you’ll deploy your changes.