Want to learn about running containers in Lambda? Join our free hands-on workshop. Register Now

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 a new index.html file with some content in it.

cat <<EOT > site/index.html
<html>
    <body>
        <h1>Hello, Pulumi!</h1>
    </body>
</html>
EOT
cat <<EOT > site/index.html
<html>
    <body>
        <h1>Hello, Pulumi!</h1>
    </body>
</html>
EOT
(
@echo.^<html^>
@echo.  ^<body^>
@echo.      ^<h1^>Hello, Pulumi!^</h1^>
@echo.  ^</body^>
@echo.^</html^>
) > site/index.html

Now that you have your new index.html with some content, open your IDE or text editor and 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 htmlString = File.ReadAllText(filePath);

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

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.