The Static Website template creates an infrastructure as code project in your favorite language that deploys an HTML website to AWS with Pulumi. It uses an [Amazon S3 bucket](/registry/packages/aws/api-docs/s3/bucket/) for file storage, configures the bucket to host a website, and deploys an [Amazon CloudFront Distribution](/registry/packages/aws/api-docs/cloudfront/distribution/) to serve the website with low latency, caching, and HTTPS. The template generates a complete Pulumi program, including placeholder web content, to give you a working project out of the box that you can customize easily and extend to suit your needs.
To use this template to deploy a website of your own, make sure you've [installed Pulumi](/docs/install/) and [configured your AWS credentials](/registry/packages/aws/installation-configuration#credentials), then create a new [project](/docs/concepts/projects/) using the template in your language of choice:
Follow the prompts to complete the new-project wizard. When it's done, you'll have a finished project that's ready to deploy and configured with the most common settings. Feel free to inspect the code in {{<langfile>}} for a closer look.
The template requires no additional configuration. Once the new project is created, you can deploy it immediately with [`pulumi up`](/docs/cli/commands/pulumi_up):
: The provider-assigned hostname of the S3 bucket.
originURL
: The fully-qualified HTTP URL of the S3 bucket endpoint.
cdnHostname
: The provider-assigned hostname of the CloudFront CDN. Useful for creating `CNAME` records to associate custom domains.
cdnURL
: The fully-qualified HTTPS URL of the CloudFront CDN.
Output values like these are useful in many ways, most commonly as inputs for other stacks or related cloud resources. The computed `cdnURL`, for example, can be used from the command line to open the newly deployed website in your favorite web browser:
: The path to the folder containing the files of the website. Defaults to `www`, which is the name (and relative path) of the folder included with the template.
indexDocument
: The file to use for top-level pages. Defaults to `index.html`.
errorDocument
: The file to use for error pages. Defaults to `error.html`.
All of these settings are optional and may be adjusted either by editing the stack configuration file directly (by default, `Pulumi.dev.yaml`) or by changing their values with [`pulumi config set`](/docs/cli/commands/pulumi_config_set) as shown below.
If you already have a static website you'd like to deploy on AWS with Pulumi, you can do so either by replacing placeholder content in the `www` folder or by configuring the stack to point to another folder on your computer with the `path` setting:
```bash
$ pulumi config set path ../my-existing-website/build
$ pulumi up
```
### Adjusting your cache settings
By default, the generated program configures the CloudFront CDN to cache files for 600 seconds (10 minutes), which may or may not be the best fit for your project or stack. You can adjust these settings by changing the code in {{<langfile>}}:
{{% chooser language "typescript,python,go,csharp,yaml" / %}}
{{% choosable language typescript %}}
```diff
const cdn = new aws.cloudfront.Distribution("cdn", {
var cdn = new Aws.CloudFront.Distribution("cdn", new()
{
DefaultCacheBehavior = new Aws.CloudFront.Inputs.DistributionDefaultCacheBehaviorArgs
{
- DefaultTtl = 600,
- MaxTtl = 600,
- MinTtl = 600,
+ DefaultTtl = 3600,
+ MaxTtl = 3600,
+ MinTtl = 3600,
```
{{% /choosable %}}
{{% choosable language yaml %}}
```diff
cdn:
type: aws:cloudfront:Distribution
properties:
defaultCacheBehavior:
- defaultTtl: 600
- maxTtl: 600
- minTtl: 600
+ defaultTtl: 600
+ maxTtl: 600
+ minTtl: 600
```
{{% /choosable %}}
Alternatively, and perhaps better, you could make these settings configurable as well, which would allow them to vary between other stacks in your project.
## Next steps
Templated projects are meant to be customized, and every web project comes with its own unique set of needs. This section includes a few examples aimed at helping you to adapt your new project to address some of the more common ones.
Once your website is deployed on AWS, you may want to give it a domain of its own. For this, you have many options, and they generally fall into one of two categories: using [Amazon Route 53](https://aws.amazon.com/route53/), which is a good choice if your domain is already being managed on AWS, or using a third-party service like [DNSimple](https://dnsimple.com) or [Google Cloud DNS](https://cloud.google.com/dns/). Both options are easily managed with Pulumi.
If the domain you'd like to use is already configured as a Route 53 [hosted zone](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/hosted-zones-working-with.html), you can easily add a subdomain for your website by making a few small changes to your program.
To do so, start by adding two new configuration settings --- one for the domain, another for subdomain to use for the website:
```bash
$ pulumi config set domain example.com
$ pulumi config set subdomain www
```
Then, in your editor of choice, open {{<langfile>}} and add the following lines to the configuration section at the top of the program to import the new settings and capture the domain as a reusable value:
Next, just above the `aws.cloudfront.Distribution` declaration, add these lines to provision and validate a new SSL/TLS certificate with [AWS Certificate Manager](https://aws.amazon.com/certificate-manager/) (ACM):
Extend the CloudFront configuration to handle requests for the new domain by adding an `aliases` argument to the CDN configuration and adjusting `viewerCertificate` to use the newly provisioned ACM certificate:
Save your changes, then preview and deploy with another `pulumi up`:
```bash
$ pulumi up
```
In a few moments, you should be able to browse to your website using the custom domain:
```bash
$ open $(pulumi stack output domainURL)
```
#### Using a third-party DNS service
If the domain you'd like to use is being managed by a third-party DNS service, you can generally use the exported `cdnHostname` to create a `CNAME` record with your DNS provider. You can obtain this value with `pulumi stack output`:
Pulumi supports many third-party DNS providers, all of which are available in the [Pulumi Registry](/registry/) and accompanied by examples, including:
Integration details vary by provider, so we suggest exploring the Pulumi API documentation of your provider of choice to learn more. [See the Registry](/registry/) for a complete list supported providers.
Congratulations! You're now well on your way to managing a production-grade static website on AWS with Pulumi --- and there's lots more you can do from here: