New example: website hosted on S3
MODIFY
README.md
README.md
@@ -6,7 +6,7 @@ Each example has a two-part prefix, `<cloud>-<language>`, to indicate which `<cl
The cloud is one of `aws` (for [Amazon Web Services](https://github.com/pulumi/pulumi-aws)), `azure` (for [Microsoft
Azure](https://github.com/pulumi/pulumi-azure)), `gcp` (for [Google Cloud
Platform](https://github.com/pulumi/pulumi-gcp)), `kubernetes` (for
-[Kubernetes](https://github.com/pulumi/pulumi-kubernetes))), or `cloud` (for
+[Kubernetes](https://github.com/pulumi/pulumi-kubernetes)), or `cloud` (for
[Pulumi's cross-cloud programming framework](https://github.com/pulumi/pulumi-cloud)).
See the [Pulumi documentation](https://docs.pulumi.com) for more details on getting started with Pulumi.
@@ -41,7 +41,7 @@ This example features an end-to-end pipeline for generating keyframe thumbnails
containerized [FFmpeg](https://www.ffmpeg.org/). It combines containers, serverless functions, and cloud storage into
a single 40-line application using `@pulumi/cloud-aws`.
-### [Raw AWS Serverless](aws-js-serverless-raw/)
+### [Raw AWS Serverless](aws-ts-serverless-raw/)
This example deploys a complete serverless C# application using raw `aws.apigateway.RestAPI`, `aws.lambda.Function` and
`aws.dynamodb.Table` resources from `@pulumi/aws`. Although this doesn't feature any of the higher-level abstractions
@@ -56,3 +56,7 @@ in a Pulumi application, even if your Pulumi code is written in a different lang
This examples shows a version of the [Kubernetes
Guestbook](https://kubernetes.io/docs/tutorials/stateless-application/guestbook/) app using Pulumi and
`@pulumi/kubernetes`.
+
+### [Static Website on AWS S3](aws-js-s3-folder/)
+
+This example deploys a static website to AWS S3, demonstrating how to combine infrastructure code and content in the same application.

ADD
aws-js-s3-folder/.gitignore
+/bin/
+/node_modules/
+/.pulumi/
+Pulumi.*.yaml

ADD
aws-js-s3-folder/Pulumi.yaml
+name: aws-js-s3-folder
+runtime: nodejs
+description: A static website hosted on AWS S3

ADD
aws-js-s3-folder/images/part2-website.png
aws-js-s3-folder/images/part2-website.png
Binary files /dev/null and b/aws-js-s3-folder/images/part2-website.png differ

ADD
aws-js-s3-folder/index.js
+"use strict";
+
+const aws = require("@pulumi/aws");
+const pulumi = require("@pulumi/pulumi");
+const mime = require("mime");
+
+// Create a bucket and expose a website index document
+let siteBucket = new aws.s3.Bucket("s3-website-bucket", {
+ websites: [{
+ indexDocument: "index.html",
+ }],
+});
+
+let siteDir = "www"; // directory for content files
+
+// For each file in the directory, create an S3 object stored in `siteBucket`
+for (let item of require("fs").readdirSync(siteDir)) {
+ let filePath = require("path").join(siteDir, item);
+ let object = new aws.s3.BucketObject(item, {
+ bucket: siteBucket, // reference the s3.Bucket object
+ source: new pulumi.asset.FileAsset(filePath), // use FileAsset to point to a file
+ contentType: mime.getType(filePath) || undefined, // set the MIME type of the file
+ });
+}
+
+// Create an S3 Bucket Policy to allow public read of all objects in bucket
+function publicReadPolicyForBucket(bucketName) {
+ return JSON.stringify({
+ Version: "2012-10-17",
+ Statement: [{
+ Effect: "Allow",
+ Principal: "*",
+ Action: [
+ "s3:GetObject"
+ ],
+ Resource: [
+ `arn:aws:s3:::${bucketName}/*` // policy refers to bucket name explicitly
+ ]
+ }]
+ })
+}
+
+// Set the access policy for the bucket so all objects are readable
+let bucketPolicy = new aws.s3.BucketPolicy("bucketPolicy", {
+ bucket: siteBucket.bucket, // refer to the bucket created earlier
+ policy: siteBucket.bucket.apply(publicReadPolicyForBucket) // use output property `siteBucket.bucket`
+});
+
+// Stack exports
+exports.bucketName = siteBucket.bucket;
+exports.websiteUrl = siteBucket.websiteEndpoint;

ADD
aws-js-s3-folder/package.json
+{
+ "name": "aws-js-s3-folder",
+ "main": "index.js",
+ "dependencies": {
+ "@pulumi/aws": "^0.11.0",
+ "@pulumi/pulumi": "^0.11.0",
+ "mime": "^2.2.2"
+ }
+}

ADD
aws-js-s3-folder/www/favicon.png
aws-js-s3-folder/www/favicon.png
Binary files /dev/null and b/aws-js-s3-folder/www/favicon.png differ

New example: website hosted on S3 (#39)