Sean Holung 026234bdbb
revert get started experience (#3076)
* add back getting started page

* decollapse getting started guide

* update style

* remove quickstart files

scss file

* lint

* assets

* update links

* update links

* update links

* update links

* update link
2023-06-16 14:10:53 -07:00

4.9 KiB

title_tag, title, h1, meta_desc, weight, menu, aliases
title_tag title h1 meta_desc weight menu aliases
Modify the Program | AWS Modify program Pulumi & AWS: Modify program This page provides an overview on how to update an AWS project from a Pulumi program. 6
clouds
parent identifier
aws-get-started aws-get-started-modify-program
/docs/quickstart/aws/modify-program/
/docs/get-started/aws/modify-program/

Now that your S3 bucket is provisioned, let's add a file to it. First, from within your project directory, create a new file called index.html file along with some content:

{{< chooser os "macos,linux,windows" / >}}

{{% choosable os macos %}}

echo '<html>
    <body>
        <h1>Hello, Pulumi!</h1>
    </body>
</html>' > index.html

{{% /choosable %}}

{{% choosable os linux %}}

echo '<html>
    <body>
        <h1>Hello, Pulumi!</h1>
    </body>
</html>' > index.html

{{% /choosable %}}

{{% choosable os windows %}}

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

{{% /choosable %}}

Now, open the program and add this file to the S3 bucket. To do this, you'll use Pulumi's FileAsset resource to assign the content of the file to a new BucketObject:

{{< chooser language "javascript,typescript,python,go,csharp,java,yaml" / >}}

{{% choosable language javascript %}}

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

// Create an S3 Bucket object
const bucketObject = new aws.s3.BucketObject("index.html", {
    bucket: bucket.id,
    source: new pulumi.asset.FileAsset("./index.html")
});

{{% /choosable %}}

{{% choosable language typescript %}}

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

// Create an S3 Bucket object
const bucketObject = new aws.s3.BucketObject("index.html", {
    bucket: bucket.id,
    source: new pulumi.asset.FileAsset("./index.html")
});

{{% /choosable %}}

{{% choosable language python %}}

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

# Create an S3 Bucket object
bucketObject = s3.BucketObject(
    'index.html',
    bucket=bucket.id,
    source=pulumi.FileAsset('./index.html')
)

{{% /choosable %}}

{{% choosable language go %}}

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

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

{{% /choosable %}}

{{% choosable language csharp %}}

In Program.cs, create a new BucketObject right after creating the bucket itself.

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

{{% /choosable %}}

{{% choosable language java %}}

In {{< langfile >}}, import the FileAsset, BucketObject, and BucketObjectArgs classes, then create the BucketObject right after creating the bucket itself.

package myproject;

import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.s3.Bucket;
import com.pulumi.aws.s3.BucketObject;
import com.pulumi.aws.s3.BucketObjectArgs;
import com.pulumi.asset.FileAsset;

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

            // Create an AWS resource (S3 Bucket)
            var bucket = new Bucket("my-bucket");

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

            // Export the name of the bucket
            ctx.export("bucketName", bucket.bucket());
        });
    }
}

{{% /choosable %}}

{{% choosable language "yaml" %}}

In {{< langfile >}}, create the BucketObject right below the bucket itself.

name: quickstart
runtime: yaml
description: A minimal AWS Pulumi YAML program

resources:
  # Create an AWS resource (S3 Bucket)
  my-bucket:
    type: aws:s3:Bucket

  # Create an S3 Bucket object
  index.html:
    type: aws:s3:BucketObject
    properties:
      bucket: ${my-bucket}
      source:
        fn::fileAsset: ./index.html

outputs:
  # Export the name of the bucket
  bucketName: ${my-bucket.id}

{{% /choosable %}}

This bucket object is part of the Bucket that we deployed earlier because we reference the bucket name in the properties of the bucket object.

We refer to this relationship as the BucketObject being a child resource of the S3 Bucket that is the parent resource. This is how Pulumi knows what S3 bucket the object should live in.

Next, you'll deploy your changes.

{{< get-started-stepper >}}