Modify the Program

Now that your S3 bucket is provisioned, let’s add an object to it. First, from within your project directory, create a new index.html file with some content in it.

cat <<EOT > index.html
<html>
    <body>
        <h1>Hello, Pulumi!</h1>
    </body>
</html>
EOT
cat <<EOT > index.html
<html>
    <body>
        <h1>Hello, Pulumi!</h1>
    </body>
</html>
EOT
@"
<html>
  <body>
    <h1>Hello, Pulumi!</h1>
  </body>
</html>
"@ | Out-File -FilePath index.html

Now that you have your new index.html with some content, open your program file and modify it to add the contents of your index.html file to your S3 bucket.

To accomplish this, you will use Pulumi’s FileAsset class to assign the content of the file to a new BucketObject.

In index.js, create the BucketObject right after creating the bucket itself.

const bucketObject = new aws.s3.BucketObject("index.html", {
    bucket: bucket,
    source: new pulumi.asset.FileAsset("index.html")
});

In index.ts, create the BucketObject right after creating the bucket itself.

const bucketObject = new aws.s3.BucketObject("index.html", {
    bucket: bucket,
    source: new pulumi.asset.FileAsset("index.html")
});

In __main__.py, create a new bucket object by adding the following right after creating the bucket itself:

bucketObject = s3.BucketObject(
    'index.html',
    bucket=bucket.id,
    source=pulumi.FileAsset('index.html')
)

In main.go, create the BucketObject right after creating the bucket itself.

_, err = s3.NewBucketObject(ctx, "index.html", &s3.BucketObjectArgs{
    Bucket:  bucket.ID(),
    Source: pulumi.NewFileAsset("index.html"),
})
if err != nil {
    return err
}

In MyStack.cs, create the BucketObject right after creating the bucket itself.

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

In index.js index.ts main.py main.go MyStack.cs Program.fs MyStack.vb App.java Pulumi.yaml , import the FileAsset, BucketObject, and BucketObjectArgs classes, then create the BucketObject right after creating the bucket itself.

// ...
import com.pulumi.asset.FileAsset;
import com.pulumi.aws.s3.BucketObject;
import com.pulumi.aws.s3.BucketObjectArgs;

public class App {
    public static void main(String[] args) {
        Pulumi.run(ctx -> {
            // var bucket = ...

            // Create an S3 Bucket object
            new BucketObject("index.html", BucketObjectArgs.builder()
                .bucket(bucket.getId())
                .source(new FileAsset("index.html"))
                .build()
            );

In index.js index.ts main.py main.go MyStack.cs Program.fs MyStack.vb App.java Pulumi.yaml , create the BucketObject right below the bucket itself.

resources:
  # ...
  index.html:
    type: aws:s3:BucketObject
    properties:
      bucket: ${my-bucket}
      source:
        Fn::FileAsset: ./index.html

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.