Pulumi & 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:
echo '<html>
<body>
<h1>Hello, Pulumi!</h1>
</body>
</html>' > index.html
echo '<html>
<body>
<h1>Hello, Pulumi!</h1>
</body>
</html>' > index.html
@"
<html>
<body>
<h1>Hello, Pulumi!</h1>
</body>
</html>
"@ | Out-File -FilePath index.html
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
:
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")
});
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")
});
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')
)
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
}
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")
});
In index.js
index.ts
main.py
main.go
Program.cs
Program.fs
Program.vb
App.java
Pulumi.yaml
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());
});
}
}
In index.js
index.ts
main.py
main.go
Program.cs
Program.fs
Program.vb
App.java
Pulumi.yaml
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}
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.
Thank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.