aws-web-pub v1.5.0
aws-web-pub
Publish a static website to AWS with one simple command.
With one simple command this tool provisions all of the AWS resources required to host your static website with a custom domain. The initial deployment takes about 10 minutes but site updates usually complete in just a few minutes.
Noteworthy Features
- Automatically generates an SSL/TLS certificate for your domain
- Supports traditional websites and single-page applications
- Supports redirecting to or from the APEX (naked) domain (e.g. have
https://example.comredirect tohttps://www.example.comor vice versa) - Redirects all
httprequests tohttps - Tear down your website and delete all AWS resources with one command
Prerequisites
Your domain(s) is managed by AWS Route 53
Your AWS credentials are configured with the AWS CLI OR you have following environment variables set to appropriate values:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY
Quick Start
Install
npm install aws-web-pubAdd a config file to the root of your project named
.aws-web-pub.json
{
"projectName": "example-site",
"publishDir": "dist",
"notFoundPath": "/404.html",
"domains": [
{
"name": "www.example.com"
}
]
}- Add convenience scripts to
package.jsonlike
{
"scripts": {
"deploy": "aws-web-pub deploy",
"destroy": "awe-web-pub destroy"
}
}Deploy your site with
npm run deployTear down your site (and delete the AWS resources) with
npm run destroy
Configuration File Options
{
"projectName": "example-site",
"publishDir": "dist",
"deleteOldFiles": true,
"notFoundPath": "/404.html",
"isSinglePageApp": false,
"domains": [
{
"name": "www.example.com"
},
{
"name": "example.com",
"dnsZoneName": "example.com"
}
],
"certificateArn": "arn:aws:acm:region:account:certificate/123456789012-1234-1234-1234-12345678"
}projectNameuniquely identifies a project within an AWS account. It must start with an alphabetic character (ASCII) and can't be longer than 128 characters. If you try to deploy more than one site with the sameprojectNamethey will overwrite each other. Note that internally all non-alphanumeric characters are converted to hyphens so projects with namesmy projectandmy-projectare considered identical and would overwrite each other.publishDiris a path to the directory of web assets to publish. This should be relative to the configuration file.deleteOldFilesis optional and indicates whether old files (files that are in the S3 bucket but not inpublishDir) should be deleted. This defaults totrue.notFoundPathis optional and identifies an html file to use for the content of 404 responses. This should be relative topublishDirand prefixed with a/. This property is ignored whenisSinglePageAppis set totrue.isSinglePageAppis optional and when set totrueit optimizes the configuration for single page applications. In this mode404errors are converted to200and return the root document. When this is enabled thenotFoundPathproperty is ignored.domainsis an optional array and describes custom domains to use. The first entry will be the primary domain and any subsequent entries will be configured to redirect to the primary. If this property is not set you can still access the site via a CloudFront URL.nameis the domain namednsZoneNameis optional and identifies the Route 53 HostedZone that manages this domain. WhendnsZoneNameis not provided it defaults to the parent domain (e.g. the domain namewww.example.comdefaults to usingexample.comas thednsZoneName). This is typically used to support the APEX / naked domain by settingnameanddnsZoneNameto the same value. In the example configuration above the APEX domainhttps://example.comwould redirect to the primary domainhttps://www.example.com
certificateArnis optional and specifies the ARN of an AWS ACM certificate to use. This certificate must be valid for every domain in thedomainssetting. If present we use this certificate instead of generating a new one (See Additional Notes below regarding AWS certificate limits).
Additional Notes
- This tool generates temporary files in a directory called
aws-web-pub.out. You should add this to.gitignore - Due to CloudFront limitations the website will always be hosted in the
us-east-1AWS region. - If you are using AWS named profiles you can pass a
--profileoption - By default most AWS Accounts can generate just 20 ACM certficates per year. If you plan on destroying sites frequently you should manually generate a certificate and use the
certificateArnto prevent hitting this limit. Alternatively you can also ask AWS support to increase your ACM "Imported certificates in last 365 days" quota limit.