Where BUCKET_NAME is the name you specified for the bucket and AWS_REGION is the region you created the bucket in.
For example, if the bucket was called foo and you deployed it in us-east-1, the URL would be:
foo.s3-website-us-east-1.amazonaws.com
If you set var.create_route53_entry to true, then this module will create a DNS A record in Route
53 for your S3 bucket with the domain name in var.website_domain_name, and you will
be able to use that custom domain name to access your bucket instead of the amazonaws.com domain.
How to configure HTTPS (SSL) or a CDN?
By default, the static content in an S3 bucket is only accessible over HTTP. To be able to access it over HTTPS, you
need to deploy a CloudFront distribution in front of the S3 bucket. This will also act as a Content Distribution
Network (CDN), which will reduce latency for your users. You will need to set the use_with_cloudfront parameter to
true.
If you are using your S3 bucket for both the www. and root domain of a website (e.g. www.foo.com and foo.com),
you need to create two buckets. One of the buckets contains the actual static content. The other sets the
should_redirect_all_requests parameter to true and sets the redirect_all_requests_to parameter to the URL of the
first site. See the Setting Up a Static Website Using a Custom
Domain documentation
for more info.
NOTE #1: due to a bug in Terraform, you
CANNOT pass multiple origins in the allowed_origins parameter! Instead, add a separate entry to cors_rule for each
origin.
NOTE #2: if you're also using the s3-cloudfront module, you MUST forward the Origin header using the
forward_headers parameter or CORS won't work!
module"s3_cloudfront" {
source = "git::git@github.com:gruntwork-io/package-static-assets.git//modules/s3-cloudfront?ref=<VERSION>"# ... other params omitted ...# MUST be specified or CORS won't work
forward_headers = ["Origin"]
}
Questions? Ask away.
We're here to talk about our services, answer any questions, give advice, or just to chat.
{"treedata":{"name":"root","toggled":true,"children":[{"name":".circleci","children":[{"name":"config.yml","path":".circleci/config.yml","sha":"a13b7823aa66e7dc9796b1a0968c6842812b688b"}]},{"name":".gitignore","path":".gitignore","sha":"42cd2961e573dc1870292a576ddbb7d4d07cca6a"},{"name":"CODEOWNERS","path":"CODEOWNERS","sha":"3ecd122c94290b76da682aaed029538b08f61ad3"},{"name":"LICENSE.txt","path":"LICENSE.txt","sha":"f4e3d9bd4717a044ed31ad847a300eee74371a78"},{"name":"README.md","path":"README.md","sha":"a940fce1a435db01e0a90343bc30fbc1664d573a"},{"name":"examples","children":[{"name":"bin","children":[{"name":"s3-upload.sh","path":"examples/bin/s3-upload.sh","sha":"616167707b12a9ed678286f6829d06ae39b8bfb0"}]},{"name":"cloudfront-s3-private-origin-group","children":[{"name":"README.md","path":"examples/cloudfront-s3-private-origin-group/README.md","sha":"a0c7c49eb8bb405624377174bf28c48e806baf44"},{"name":"main.tf","path":"examples/cloudfront-s3-private-origin-group/main.tf","sha":"51877c4cc06db781a2c99749d9e0cbc5f01420aa"},{"name":"outputs.tf","path":"examples/cloudfront-s3-private-origin-group/outputs.tf","sha":"7ad8a7de25248890dd41ec74575fb18e206cf93b"},{"name":"vars.tf","path":"examples/cloudfront-s3-private-origin-group/vars.tf","sha":"58848af7c7064fe5054c4612f3f48911db5182eb"}]},{"name":"cloudfront-s3-private","children":[{"name":"README.md","path":"examples/cloudfront-s3-private/README.md","sha":"03ae92790de376455152698d267caf86d2348911"},{"name":"main.tf","path":"examples/cloudfront-s3-private/main.tf","sha":"b1a2b439919792ba08cdf48d839da9015a9ec484"},{"name":"outputs.tf","path":"examples/cloudfront-s3-private/outputs.tf","sha":"4028b7c112eb547208079b450305f8560d451deb"},{"name":"vars.tf","path":"examples/cloudfront-s3-private/vars.tf","sha":"a425384eeb20791743b66aed98f96ab5c71a6dba"}]},{"name":"cloudfront-s3-public-origin-group","children":[{"name":"README.md","path":"examples/cloudfront-s3-public-origin-group/README.md","sha":"80e5a99578d8c9eba230531ac040a8e82aebfebd"},{"name":"main.tf","path":"examples/cloudfront-s3-public-origin-group/main.tf","sha":"7cb1c4b8b89cb3bf7db1173cca92e26c28153f90"},{"name":"outputs.tf","path":"examples/cloudfront-s3-public-origin-group/outputs.tf","sha":"7ad8a7de25248890dd41ec74575fb18e206cf93b"},{"name":"vars.tf","path":"examples/cloudfront-s3-public-origin-group/vars.tf","sha":"627d6c64c757b21e2b4ac175dfa72a9cf4df36b9"}]},{"name":"cloudfront-s3-public","children":[{"name":"README.md","path":"examples/cloudfront-s3-public/README.md","sha":"aed32ebaa3e145939ee0e027125583200673c104"},{"name":"main.tf","path":"examples/cloudfront-s3-public/main.tf","sha":"b5da2cc4e56ab3298c0a97251acb386e5737f0b8"},{"name":"outputs.tf","path":"examples/cloudfront-s3-public/outputs.tf","sha":"4028b7c112eb547208079b450305f8560d451deb"},{"name":"vars.tf","path":"examples/cloudfront-s3-public/vars.tf","sha":"c2b9d004a3437603f884e2e043e3a95a0d9623e4"}]},{"name":"example-website","children":[{"name":"README.md","path":"examples/example-website/README.md","sha":"359ae6d06f8e77244f18c42704637b8e6ef498c6"},{"name":"error.html","path":"examples/example-website/error.html","sha":"b2b8878e00a2f707b709ae699ce466c543eab954"},{"name":"grunty.png","path":"examples/example-website/grunty.png","sha":"fa4bab8d46d843cd22b20f16bcda72e9d4c86680"},{"name":"index.html","path":"examples/example-website/index.html","sha":"a7a486627108114d5ca4a21f856e3b410c6b73e2"}]},{"name":"s3-static-website","children":[{"name":"README.md","path":"examples/s3-static-website/README.md","sha":"a2d9c34b338551214ccf7df40d63bfa98ae5bae6"},{"name":"main.tf","path":"examples/s3-static-website/main.tf","sha":"307eb8cc97c3d9fa63e5dbf7d22f5b351d433d63"},{"name":"outputs.tf","path":"examples/s3-static-website/outputs.tf","sha":"7c6be384ebcdb5c66d9432617ae165919160e006"},{"name":"vars.tf","path":"examples/s3-static-website/vars.tf","sha":"ac474a07ba42f7c39459d1a2a746a3ae3bf543ef"}]}]},{"name":"modules","children":[{"name":"_docs","children":[{"name":"s3-architecture.png","path":"modules/_docs/s3-architecture.png","sha":"24664de39064d5c6767105b75d002bddf763ff82"},{"name":"s3.png","path":"modules/_docs/s3.png","sha":"667a181c90817858914551e9b2fa376fa1c8f177"}]},{"name":"s3-cloudfront","children":[{"name":"README.md","path":"modules/s3-cloudfront/README.md","sha":"5b69068481d80e58832ea79b945458ce392e6ad7"},{"name":"main.tf","path":"modules/s3-cloudfront/main.tf","sha":"17839e57dc562cad59d5f29b1ca719850727b5eb"},{"name":"outputs.tf","path":"modules/s3-cloudfront/outputs.tf","sha":"fb0e7380080e2b16420ac47f255841ce468686cb"},{"name":"vars.tf","path":"modules/s3-cloudfront/vars.tf","sha":"5fcd3e9ca4773ee70d4e19d4c98bd412c223777d"}]},{"name":"s3-static-website","children":[{"name":"README.adoc","path":"modules/s3-static-website/README.adoc","sha":"e44d0ebedbc22053b54d9b65087d5f83c4886520"},{"name":"core-concepts.md","path":"modules/s3-static-website/core-concepts.md","sha":"1cb65fe1aeb7081449431c56a8fc7dc5ba05007b","toggled":true},{"name":"main.tf","path":"modules/s3-static-website/main.tf","sha":"6e6484a4673c538335609539fd980b6b017426f4"},{"name":"outputs.tf","path":"modules/s3-static-website/outputs.tf","sha":"f51e55aba8a05668e2cfb88de5a169c5dee5c973"},{"name":"vars.tf","path":"modules/s3-static-website/vars.tf","sha":"99d70c07514e062fcfff87c4ea1b4d115e48daa1"}],"toggled":true}],"toggled":true},{"name":"test","children":[{"name":"Gopkg.lock","path":"test/Gopkg.lock","sha":"03773d142d1feac30669f3c13032d289d9e3a398"},{"name":"Gopkg.toml","path":"test/Gopkg.toml","sha":"a84c6ed7e5bfce6f72e9e08666f1665af01a3f84"},{"name":"README.md","path":"test/README.md","sha":"677e87a94c28a43bc370cf3641fa5390a3cd3b63"},{"name":"s3_cloudfront_canonical_user_test.go","path":"test/s3_cloudfront_canonical_user_test.go","sha":"cdddc74e688c82fffea183946fe0ed3d66581de8"},{"name":"s3_cloudfront_origin_group_test.go","path":"test/s3_cloudfront_origin_group_test.go","sha":"46aa9d45071a6d563596e131df875d34df054532"},{"name":"s3_cloudfront_test.go","path":"test/s3_cloudfront_test.go","sha":"bd6afba183d1d17670746c3040a2d87f9e6246ee"},{"name":"s3_static_website_test.go","path":"test/s3_static_website_test.go","sha":"461fa4b7cda579a8402e441733618b759c5222c0"},{"name":"test_helpers.go","path":"test/test_helpers.go","sha":"13abdb0c2881ad74383328a6b7966a6c0a7fb7ce"}]}]},"detailsContent":"<h2 class=\"preview__body--subtitle\" id=\"quick-start\">Quick Start</h2>\n<ul>\n<li>See the <a href=\"/repos/v0.6.3/package-static-assets/examples/s3-static-website\" class=\"preview__body--description--blue\">s3-static-website example</a> for working sample code.</li>\n<li>Check out <a href=\"/repos/v0.6.3/package-static-assets/modules/s3-static-website/vars.tf\" class=\"preview__body--description--blue\">vars.tf</a> for all parameters you can set for this module.</li>\n</ul>\n<h2 class=\"preview__body--subtitle\" id=\"how-to-test-the-website\">How to test the website?</h2>\n<p>This module outputs the domain name of your website using the <code>website_domain_name</code> output variable.</p>\n<p>By default, the domain name will be of the form:</p>\n<pre><span class=\"hljs-symbol\"><BUCKET_NAME></span>.s3-website-<span class=\"hljs-symbol\"><AWS_REGION></span>.amazonaws.<span class=\"hljs-keyword\">com</span>/\n</pre>\n<p>Where <code>BUCKET_NAME</code> is the name you specified for the bucket and <code>AWS_REGION</code> is the region you created the bucket in.\nFor example, if the bucket was called <code>foo</code> and you deployed it in <code>us-east-1</code>, the URL would be:</p>\n<pre><span class=\"hljs-selector-tag\">foo</span><span class=\"hljs-selector-class\">.s3-website-us-east-1</span><span class=\"hljs-selector-class\">.amazonaws</span><span class=\"hljs-selector-class\">.com</span>\n</pre>\n<p>If you set <code>var.create_route53_entry</code> to true, then this module will create a DNS A record in <a href=\"https://aws.amazon.com/route53/\" class=\"preview__body--description--blue\" target=\"_blank\">Route\n53</a> for your S3 bucket with the domain name in <code>var.website_domain_name</code>, and you will\nbe able to use that custom domain name to access your bucket instead of the <code>amazonaws.com</code> domain.</p>\n<h2 class=\"preview__body--subtitle\" id=\"how-to-configure-https-ssl-or-a-cdn\">How to configure HTTPS (SSL) or a CDN?</h2>\n<p>By default, the static content in an S3 bucket is only accessible over HTTP. To be able to access it over HTTPS, you\nneed to deploy a CloudFront distribution in front of the S3 bucket. This will also act as a Content Distribution\nNetwork (CDN), which will reduce latency for your users. You will need to set the <code>use_with_cloudfront</code> parameter to\n<code>true</code>.</p>\n<p>To set up a CloudFront distribution, see the <a href=\"/repos/v0.6.3/package-static-assets/modules/s3-cloudfront\" class=\"preview__body--description--blue\">s3-cloudfront module</a>.</p>\n<h2 class=\"preview__body--subtitle\" id=\"how-do-i-handle-www-root-domains\">How do I handle www + root domains?</h2>\n<p>If you are using your S3 bucket for both the <code>www.</code> and root domain of a website (e.g. <code>www.foo.com</code> and <code>foo.com</code>),\nyou need to create two buckets. One of the buckets contains the actual static content. The other sets the\n<code>should_redirect_all_requests</code> parameter to <code>true</code> and sets the <code>redirect_all_requests_to</code> parameter to the URL of the\nfirst site. See the <a href=\"http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html\" class=\"preview__body--description--blue\" target=\"_blank\">Setting Up a Static Website Using a Custom\nDomain</a> documentation\nfor more info.</p>\n<p><a href=\"#how-do-i-configure-cross-origin-resource-sharing-cors\" class=\"preview__body--description--blue\">foo</a></p>\n<h2 class=\"preview__body--subtitle\" id=\"how-do-i-configure-cross-origin-resource-sharing-cors\">How do I configure Cross Origin Resource Sharing (CORS)?</h2>\n<p>To enable <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS\" class=\"preview__body--description--blue\" target=\"_blank\">Cross Origin Resource Sharing (CORS)</a>, you need to\nset the <code>cors_rule</code> parameter in this module:</p>\n<pre><span class=\"hljs-keyword\">module</span> <span class=\"hljs-string\">\"s3_static_website\"</span> {\n source = <span class=\"hljs-string\">\"git::git@github.com:gruntwork-io/package-static-assets.git//modules/s3-static-website?ref=<VERSION>\"</span>\n\n <span class=\"hljs-comment\"># ... other params omitted ...</span>\n\n <span class=\"hljs-comment\"># CORS settings</span>\n cors_rule = [\n {\n allowed_headers = [<span class=\"hljs-string\">\"*\"</span>]\n allowed_methods = [<span class=\"hljs-string\">\"GET\"</span>]\n allowed_origins = [<span class=\"hljs-string\">\"www.your-domain.com\"</span>]\n expose_headers = [<span class=\"hljs-string\">\"ETag\"</span>,<span class=\"hljs-string\">\"Origin\"</span>,<span class=\"hljs-string\">\"Access-Control-Request-Headers\"</span>,<span class=\"hljs-string\">\"Access-Control-Request-Method\"</span>]\n max_age_seconds = <span class=\"hljs-number\">3000</span>\n },\n \n {\n allowed_headers = [<span class=\"hljs-string\">\"*\"</span>]\n allowed_methods = [<span class=\"hljs-string\">\"GET\"</span>]\n allowed_origins = [<span class=\"hljs-string\">\"www.another-domain.com\"</span>]\n expose_headers = [<span class=\"hljs-string\">\"ETag\"</span>,<span class=\"hljs-string\">\"Origin\"</span>,<span class=\"hljs-string\">\"Access-Control-Request-Headers\"</span>,<span class=\"hljs-string\">\"Access-Control-Request-Method\"</span>]\n max_age_seconds = <span class=\"hljs-number\">3000</span>\n }\n ] \n}\n\n</pre>\n<p><strong>NOTE #1</strong>: due to a <a href=\"https://github.com/terraform-providers/terraform-provider-aws/issues/9334\" class=\"preview__body--description--blue\" target=\"_blank\">bug in Terraform</a>, you\nCANNOT pass multiple origins in the <code>allowed_origins</code> parameter! Instead, add a separate entry to <code>cors_rule</code> for each\norigin.</p>\n<p><strong>NOTE #2</strong>: if you're also using the <code>s3-cloudfront</code> module, you MUST forward the <code>Origin</code> header using the\n<code>forward_headers</code> parameter or CORS won't work!</p>\n<pre><span class=\"hljs-keyword\">module</span> <span class=\"hljs-string\">\"s3_cloudfront\"</span> {\n source = <span class=\"hljs-string\">\"git::git@github.com:gruntwork-io/package-static-assets.git//modules/s3-cloudfront?ref=<VERSION>\"</span>\n \n <span class=\"hljs-comment\"># ... other params omitted ...</span>\n\n <span class=\"hljs-comment\"># MUST be specified or CORS won't work</span>\n forward_headers = [<span class=\"hljs-string\">\"Origin\"</span>]\n}\n</pre>\n","repoName":"package-static-assets","repoRef":"v0.5.7","serviceDescriptor":{"serviceName":"S3","serviceRepoName":"package-static-assets","serviceRepoOrg":"gruntwork-io","serviceMainReadmePath":"/modules/s3-static-website","cloudProviders":["aws"],"description":"Deploy your static content and static websites on S3. Supports bucket versioning, redirects, and access logging.","imageUrl":"amazon-s3.png","licenseType":"subscriber","technologies":["Terraform"],"compliance":[],"tags":[""]},"serviceCategoryName":"Static content","fileName":"core-concepts.md","filePath":"/modules/s3-static-website/core-concepts.md","title":"Repo Browser: S3","description":"Browse the repos in the Gruntwork Infrastructure as Code Library."}