github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/testing/test/testdata/aws-s3-folder-pp/nodejs/aws-s3-folder.ts (about)

     1  import * as pulumi from "@pulumi/pulumi";
     2  import * as aws from "@pulumi/aws";
     3  import * as fs from "fs";
     4  
     5  // Create a bucket and expose a website index document
     6  const siteBucket = new aws.s3.Bucket("siteBucket", {website: {
     7      indexDocument: "index.html",
     8  }});
     9  const siteDir = "www";
    10  // For each file in the directory, create an S3 object stored in `siteBucket`
    11  const files: aws.s3.BucketObject[] = [];
    12  for (const range of fs.readDirSync(siteDir).map((k, v) => {key: k, value: v})) {
    13      files.push(new aws.s3.BucketObject(`files-${range.key}`, {
    14          bucket: siteBucket.id,
    15          key: range.value,
    16          source: new pulumi.asset.FileAsset(`${siteDir}/${range.value}`),
    17          contentType: range.value,
    18      }));
    19  }
    20  // set the MIME type of the file
    21  // Set the access policy for the bucket so all objects are readable
    22  const bucketPolicy = new aws.s3.BucketPolicy("bucketPolicy", {
    23      bucket: siteBucket.id,
    24      policy: siteBucket.id.apply(id => JSON.stringify({
    25          Version: "2012-10-17",
    26          Statement: [{
    27              Effect: "Allow",
    28              Principal: "*",
    29              Action: ["s3:GetObject"],
    30              Resource: [`arn:aws:s3:::${id}/*`],
    31          }],
    32      })),
    33  });
    34  export const bucketName = siteBucket.bucket;
    35  export const websiteUrl = siteBucket.websiteEndpoint;