Debian Codegraph @

docs/content/en/host-and-deploy/host-on-aws-amplify/index.md

raw
1 ---
2 title: Host on AWS Amplify
3 description: Host your project on AWS Amplify.
4 categories: []
5 keywords: []
6 aliases: [/hosting-and-deployment/hosting-on-aws-amplify/]
7 ---
8
9 Use these instructions to enable continuous deployment from a GitHub repository. The same general steps apply for other Git providers such as GitLab or Bitbucket.
10
11 {{% include "/_common/gitignore-public.md" %}}
12
13 ## Prerequisites
14
15 Please complete the following tasks before continuing:
16
17 1. [Create](https://aws.amazon.com/resources/create-account/) an AWS account.
18 1. [Log in](https://console.aws.amazon.com/) to your AWS account.
19 1. [Create](https://github.com/signup) a GitHub account.
20 1. [Log in](https://github.com/login) to your GitHub account.
21 1. [Create](https://github.com/new) a GitHub repository for your project.
22 1. [Create](https://git-scm.com/docs/git-init) a local Git repository for your project with a [remote][] reference to your GitHub repository.
23 1. Create a Hugo project within your local Git repository and test it with the `hugo server` command.
24 1. Commit the changes to your local Git repository and push to your GitHub repository.
25
26 ## Procedure
27
28 Step 1
29 : Create an `amplify.yml` file in the root of your project, adjusting the tool versions and time zone as needed.
30
31 ```yaml {file="amplify.yml" copy=true}
32 version: 1
33 env:
34 variables:
35 # Define tool versions
36 DART_SASS_VERSION: 1.104.0
37 GO_VERSION: 1.27.0
38 HUGO_VERSION: 0.166.0
39 NODE_VERSION: 24.20.0
40
41 # Set the build time zone
42 TZ: Europe/Oslo
43
44 # Set the build cache directory
45 HUGO_CACHEDIR: ${PWD}/.cache/hugo
46 frontend:
47 phases:
48 preBuild:
49 commands:
50 # Create a temporary directory for downloads
51 - build_temp_dir=$(mktemp -d)
52
53 # Create a local tools directory
54 - mkdir -p "${HOME}/.local"
55
56 # Install Dart Sass
57 - |
58 echo "Installing Dart Sass ${DART_SASS_VERSION}..."
59 curl -sfL --output-dir "${build_temp_dir}" -O "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
60 tar -C "${HOME}/.local" -xf "${build_temp_dir}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
61 export PATH="${HOME}/.local/dart-sass:${PATH}"
62
63 # Install Go
64 - |
65 if [[ -f "go.mod" ]]; then
66 echo "Installing Go ${GO_VERSION}..."
67 curl -sfL --output-dir "${build_temp_dir}" -O "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz"
68 tar -C "${HOME}/.local" -xf "${build_temp_dir}/go${GO_VERSION}.linux-amd64.tar.gz"
69 export PATH="${HOME}/.local/go/bin:${PATH}"
70 fi
71
72 # Install Hugo
73 - |
74 echo "Installing Hugo ${HUGO_VERSION}..."
75 curl -sfL --output-dir "${build_temp_dir}" -O "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_linux-amd64.tar.gz"
76 mkdir -p "${HOME}/.local/hugo"
77 tar -C "${HOME}/.local/hugo" -xf "${build_temp_dir}/hugo_${HUGO_VERSION}_linux-amd64.tar.gz"
78 export PATH="${HOME}/.local/hugo:${PATH}"
79
80 # Install Node.js
81 - |
82 if [[ -f "package-lock.json" ]]; then
83 echo "Installing Node.js ${NODE_VERSION}..."
84 curl -sfL --output-dir "${build_temp_dir}" -O "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz"
85 tar -C "${HOME}/.local" -xf "${build_temp_dir}/node-v${NODE_VERSION}-linux-x64.tar.gz"
86 export PATH="${HOME}/.local/node-v${NODE_VERSION}-linux-x64/bin:${PATH}"
87 fi
88
89 # Log tool versions
90 - |
91 echo "Logging tool versions..."
92 command -v sass &> /dev/null && echo "Dart Sass: $(sass --version)" || echo "Dart Sass: not installed"
93 command -v go &> /dev/null && echo "Go: $(go version)" || echo "Go: not installed"
94 command -v hugo &> /dev/null && echo "Hugo: $(hugo version)" || echo "Hugo: not installed"
95 command -v node &> /dev/null && echo "Node.js: $(node --version)" || echo "Node.js: not installed"
96
97 # Configure Git
98 - |
99 echo "Configuring Git..."
100 git config --global core.quotepath false
101
102 # Fetch full Git history
103 - |
104 if [[ $(git rev-parse --is-shallow-repository) == true ]]; then
105 echo "Fetching full Git history..."
106 git fetch --unshallow
107 fi
108
109 # Initialize Git submodules
110 - |
111 if [[ -f .gitmodules ]]; then
112 echo "Initializing Git submodules..."
113 git submodule update --init --recursive
114 fi
115
116 # Install Node.js dependencies
117 - |
118 if [[ -f package-lock.json ]]; then
119 echo "Installing Node.js dependencies..."
120 npm ci
121 fi
122 build:
123 commands:
124 # Build the project
125 - |
126 echo "Building the project..."
127 hugo build --gc --minify
128 artifacts:
129 baseDirectory: public
130 files:
131 - '**/*'
132 cache:
133 paths:
134 - .cache/hugo/**/*
135 ```
136
137 Step 2
138 : In the project configuration file in the root of your local Git repository, set the location of the image cache to the [`cacheDir`][] as shown below.
139
140 {{< code-toggle file=hugo copy=true >}}
141 [caches.images]
142 dir = ':cacheDir/images'
143 {{< /code-toggle >}}
144
145 See [configure file caches][] for more information.
146
147 Step 3
148 : Commit and push the change to your GitHub repository.
149
150 ```sh
151 git add -A
152 git commit -m "Create amplify.yml"
153 git push
154 ```
155
156 Step 4
157 : Log in to your AWS account, navigate to the [Amplify Console][], then press the **Deploy an app** button.
158
159 Step 5
160 : Choose a source code provider, then press the **Next** button.
161
162 ![screen capture](amplify-01.png)
163
164 Step 6
165 : Authorize AWS Amplify to access your GitHub account.
166
167 ![screen capture](amplify-02.png)
168
169 Step 7
170 : Select your personal account or relevant organization.
171
172 ![screen capture](amplify-03.png)
173
174 Step 8
175 : Authorize access to one or more repositories.
176
177 ![screen capture](amplify-04.png)
178
179 Step 9
180 : Select a repository and branch, then press the **Next** button.
181
182 ![screen capture](amplify-05.png)
183
184 Step 10
185 : On the "App settings" page, scroll to the bottom then press the **Next** button. Amplify reads the `amplify.yml` file you created in Steps 1-3 instead of using the values on this page.
186
187 Step 11
188 : On the "Review" page, scroll to the bottom then press the **Save and deploy** button.
189
190 Step 12
191 : When your site has finished deploying, press the **Visit deployed URL** button to view your published site.
192
193 ![screen capture](amplify-06.png)
194
195 ## Related resources
196
197 For more information on hosting and managing your site with AWS Amplify, consult the official documentation:
198
199 - [General documentation][]
200 - [Custom domain setup][]
201
202 [Amplify Console]: https://console.aws.amazon.com/amplify/apps
203 [Custom domain setup]: https://docs.aws.amazon.com/amplify/latest/userguide/custom-domains.html
204 [General documentation]: https://docs.aws.amazon.com/amplify/latest/userguide/welcome.html
205 [`cacheDir`]: /configuration/all/#cachedir
206 [configure file caches]: /configuration/caches/
207 [remote]: https://git-scm.com/docs/git-remote