flat-chef-39475
04/06/2021, 10:46 PM"use strict";
const fs = require("fs");
const pulumi = require("@pulumi/pulumi");
const aws = require("@pulumi/aws");
const awsx = require("@pulumi/awsx");
const htmlTemplate = `<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<h1>Hi from Pulumi!</h1>
<img src="{object}"></img>
</body>
</html>`
// Create an AWS resource (S3 Bucket)
const bucket = new aws.s3.Bucket("my-bucket", {
website: {
indexDocument: "index.html"
}
});
const imgObject = new aws.s3.BucketObject("roo.jpg", {
bucket,
source: new pulumi.asset.FileAsset("roo.jpg"),
acl: "public-read",
contentType: "image/jpeg"
})
const imgUrl = pulumi.interpolate`http://${bucket.bucketEndpoint}/roo.jpg`
const html = htmlTemplate.replace("{object}", imgUrl)
fs.writeFileSync("index.html", html)
const indexObject = new aws.s3.BucketObject("index.html", {
bucket,
source: new pulumi.asset.FileAsset("index.html"),
acl: "public-read",
contentType: "text/html"
})
// Export the name of the bucket
exports.bucketName = bucket.id;
exports.bucketEndpoint = pulumi.interpolate`http://${bucket.websiteEndpoint}`;