Deployment with Amazon S3 and CloudFront
There are several options for publishing your web site using Amazon Web Services. This section describes the most basic option, deploying your site using an S3 bucket and activating the CloudFront CDN (content delivery network) to speed up the delivery of your deployed contents.
After your registration at AWS, create your S3 bucket, connect it with your domain, and add it to the CloudFront CDN. This blog post has all the details and provides easy to follow step-by-step instructions for the whole procedure.
Download and install the latest version 2 of the AWS Command Line Interface (CLI). Then configure your CLI instance by issuing the command
aws configure(make sure you have your AWS Access Key ID and your AWS Secret Access Key at hand):$ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: eu-central-1 Default output format [None]:Check the proper configuration of your AWS CLI by issuing the command
aws s3 ls, this should output a list of your S3 bucket(s).
Inside your
hugo.toml/hugo.yaml/hugo.json, add a[deployment]section like this one:[deployment] [[deployment.targets]] name = "aws" URL = "s3://www.your-domain.tld" cloudFrontDistributionID = "E9RZ8T1EXAMPLEID"deployment: targets: - name: aws URL: 's3://www.your-domain.tld' cloudFrontDistributionID: E9RZ8T1EXAMPLEID{ "deployment": { "targets": [ { "name": "aws", "URL": "s3://www.your-domain.tld", "cloudFrontDistributionID": "E9RZ8T1EXAMPLEID" } ] } }
Run the command
hugo --gc --minifyto render the site’s assets into thepublic/directory of your Hugo build environment.Use Hugo’s built-in
deploycommand to deploy the site to S3:hugo deploy Deploying to target "aws" (www.your-domain.tld) Identified 77 file(s) to upload, totaling 5.3 MB, and 0 file(s) to delete. Success! Invalidating CloudFront CDN... Success!As you can see, issuing the
hugo deploycommand automatically invalidates your CloudFront CDN cache.That’s all you need to do! From now on, you can easily deploy to your S3 bucket using Hugo’s built-in
deploycommand!
For more information about the Hugo deploy command, including command line
options, see this synopsis. In
particular, you may find the --maxDeletes int option or the --force option
(which forces upload of all files) useful.
If the source of your site lives in a GitHub repository, you can use GitHub Actions to deploy the site to your S3 bucket as soon as you commit changes to your GitHub repo. Setup of this workflow is described in this blog post.
If S3 does not meet your needs, consider AWS Amplify Console. This is a more advanced continuous deployment (CD) platform with built-in support for the Hugo static site generator. A starter can be found in Hugo’s official docs.
Feedback
Cette page est-elle utile?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.