- Hosting buckets are ideal for serving static content(such as static website) and client rendered applications to your users across the world.
- Contents of your application are distributed through CDN. By distributing and caching content across 310+ globally dispersed Points of Presence (PoPs - also called edge locations) you can significantly decrease the latency of data delivery as well as reduce load on your application.
- Hosting buckets come secured(with automatic TLS) out of the box
- If your use-case requires more control over bucket configuration take a look at the bucket resource.
Under the hood
Under the hood, the hosting bucket has two main components:
You can configure properties hosting bucket by simply setting upload directory path:
Path to the directory that contains content you wish to host.
This can be output directory of your website build process(built website) or any other directory containing static content you wish to serve.
bucket:synccommands, contents of the folder is uploaded to the bucket
Copyresources:myWebsite:type: 'hosting-bucket'properties:uploadDirectoryPath: ./dist
Hosting content type
You can specify what type of content type you are hosting.
Based of that Stacktape will configure HTTP headers of uploaded files and CDN behavior.
Supported content types:
cache-controlheader value for all uploaded files to
public, max-age=0, s-maxage=31536000, must-revalidate.
- this setup caches all the content on the CDN but never caches files in the browser.
- optimizes headers for a Single page application
htmlfiles are never cached (so that when you re-deploy your website, your users always get the latest content)
- All other assets (.js, .css, etc.) are cached indefinitely. You should ALWAYS add a content hash to the filename, so that your users always get a new version of your website after you deploy it. To learn how to add a content hash to your files, refer to the docs of your bundler, for example webpack docs.
- Sets up correct CDN redirects for single page app.
Copyresources:myWebsite:type: hosting-bucketproperties:uploadDirectoryPath: ./disthostingContentType: single-page-app
Connecting a custom domain to the resource does 2 things:
- Creates DNS records:
- If you use your custom domain with a resource, Stacktape automatically creates a DNS record (during deploy) pointing the specified domain name to the resource.
- Adds TLS certificates
- Stacktape takes care of issuing and attaching correct (free, AWS-managed) certificate to the resource. This means, you do not have to deal with TLS termination(HTTPS).
- If you want to use your own certificates, you can configure
To manage a custom domain, it first needs to be added to your AWS account. This means that a hosted zone (collection of records managed together for a given domain) for your domain exists in your AWS account and your domain registrar's name servers are pointing to it. To learn more, refer to Adding a domain guide.
Copyresources:myWebsite:type: hosting-bucketproperties:uploadDirectoryPath: ./disthostingContentType: single-page-appcustomDomains:- domainName: example.com
Edge lambda functions
You can associate
edge-lambda-functionwith hosting-bucket to be executed:
onRequest- function is executed when CDN receives a request from a client(viewer) before checking CDN cache and before request is forwarded to hosting-bucket
onResponse- function is executed before returning the response to the client(viewer)
Potential use-cases for using edge functions:
- generating immediate HTTP response without the need to check CDN cache or forward to the bucket
- modifying request (i.e rewrite url, headers etc) before forwarding to the bucket
For more information refer to Edge lambda functions page.
Copyresources:authFunction:type: edge-lambda-functionproperties:packaging:type: stacktape-lambda-buildpackproperties:entryfilePath: auth-function.tsmyWebsite:type: hosting-bucketproperties:edgeFunctions:onRequest: authFunction
The following parameters can be easily referenced using $ResourceParam directive directive.
To learn more about referencing parameters, refer to referencing parameters.
AWS (physical) name of the bucket
Arn of the bucket
Default domain of the CDN distribution (only available if you DO NOT configure custom domain names for the CDN).
Default url of the CDN distribution (only available if you DO NOT configure custom domain names for the CDN).
Comma-separated list of custom domain names assigned to the CDN (only available if you configure custom domain names for the CDN).
Comma-separated list of custom domain name URLs of the CDN (only available if you configure custom domain names for the CDN).