aws-web-pub
v1.5.0
Published
Publish a static website to AWS with one simple command.
Downloads
14
Maintainers
Readme
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.com
redirect tohttps://www.example.com
or vice versa) - Redirects all
http
requests 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_ID
AWS_SECRET_ACCESS_KEY
Quick Start
Install
npm install aws-web-pub
Add 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.json
like
{
"scripts": {
"deploy": "aws-web-pub deploy",
"destroy": "awe-web-pub destroy"
}
}
Deploy your site with
npm run deploy
Tear 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"
}
projectName
uniquely 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 sameprojectName
they will overwrite each other. Note that internally all non-alphanumeric characters are converted to hyphens so projects with namesmy project
andmy-project
are considered identical and would overwrite each other.publishDir
is a path to the directory of web assets to publish. This should be relative to the configuration file.deleteOldFiles
is optional and indicates whether old files (files that are in the S3 bucket but not inpublishDir
) should be deleted. This defaults totrue
.notFoundPath
is optional and identifies an html file to use for the content of 404 responses. This should be relative topublishDir
and prefixed with a/
. This property is ignored whenisSinglePageApp
is set totrue
.isSinglePageApp
is optional and when set totrue
it optimizes the configuration for single page applications. In this mode404
errors are converted to200
and return the root document. When this is enabled thenotFoundPath
property is ignored.domains
is 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.name
is the domain namednsZoneName
is optional and identifies the Route 53 HostedZone that manages this domain. WhendnsZoneName
is not provided it defaults to the parent domain (e.g. the domain namewww.example.com
defaults to usingexample.com
as thednsZoneName
). This is typically used to support the APEX / naked domain by settingname
anddnsZoneName
to the same value. In the example configuration above the APEX domainhttps://example.com
would redirect to the primary domainhttps://www.example.com
certificateArn
is optional and specifies the ARN of an AWS ACM certificate to use. This certificate must be valid for every domain in thedomains
setting. 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-1
AWS region. - If you are using AWS named profiles you can pass a
--profile
option - 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
certificateArn
to prevent hitting this limit. Alternatively you can also ask AWS support to increase your ACM "Imported certificates in last 365 days" quota limit.