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 site 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 if you are using GitLab for version control.
10
11 ## Prerequisites
12
13 Please complete the following tasks before continuing:
14
15 1. [Create](https://aws.amazon.com/resources/create-account/) an AWS account
16 1. [Log in](https://console.aws.amazon.com/) to your AWS account
17 1. [Create](https://github.com/signup) a GitHub account
18 1. [Log in](https://github.com/login) to your GitHub account
19 1. [Create](https://github.com/new) a GitHub repository for your project
20 1. [Create](https://git-scm.com/docs/git-init) a local Git repository for your project with a [remote](https://git-scm.com/docs/git-remote) reference to your GitHub repository
21 1. Create a Hugo project within your local Git repository and test it with the `hugo server` command
22 1. Commit the changes to your local Git repository and push to your GitHub repository.
23
24 ## Procedure
25
26 This procedure will enable continuous deployment from a GitHub repository. The procedure is essentially the same if you are using GitLab or Bitbucket.
27
28 Step 1
29 : Create a file named `amplify.yml` in the root of your project.
30
31 ```sh
32 touch amplify.yml
33 ```
34
35 Step 2
36 : Copy and paste the YAML below into the file you created. Change the application versions and time zone as needed.
37
38 ```yaml {file="amplify.yml" copy=true}
39 version: 1
40 env:
41 variables:
42 # Application versions
43 DART_SASS_VERSION: 1.99.0
44 GO_VERSION: 1.26.2
45 HUGO_VERSION: 0.161.1
46 # Time zone
47 TZ: Europe/Oslo
48 # Cache
49 HUGO_CACHEDIR: ${PWD}/.hugo
50 NPM_CONFIG_CACHE: ${PWD}/.npm
51 frontend:
52 phases:
53 preBuild:
54 commands:
55 # Create directory for user-specific executable files
56 - echo "Creating directory for user-specific executable files..."
57 - mkdir -p "${HOME}/.local"
58
59 # Install Dart Sass
60 - echo "Installing Dart Sass ${DART_SASS_VERSION}..."
61 - curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
62 - tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
63 - rm "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
64 - export PATH="${HOME}/.local/dart-sass:${PATH}"
65
66 # Install Go
67 - echo "Installing Go ${GO_VERSION}..."
68 - curl -sLJO "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz"
69 - tar -C "${HOME}/.local" -xf "go${GO_VERSION}.linux-amd64.tar.gz"
70 - rm "go${GO_VERSION}.linux-amd64.tar.gz"
71 - export PATH="${HOME}/.local/go/bin:${PATH}"
72
73 # Install Hugo
74 - echo "Installing Hugo ${HUGO_VERSION}..."
75 - curl -sLJO "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
76 - mkdir "${HOME}/.local/hugo"
77 - tar -C "${HOME}/.local/hugo" -xf "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
78 - rm "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
79 - export PATH="${HOME}/.local/hugo:${PATH}"
80
81 # Verify installations
82 - echo "Verifying installations..."
83 - "echo Dart Sass: $(sass --version)"
84 - "echo Go: $(go version)"
85 - "echo Hugo: $(hugo version)"
86 - "echo Node.js: $(node --version)"
87
88 # Install Node.js dependencies
89 - echo "Installing Node.js dependencies..."
90 - "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci --prefer-offline || true"
91
92 # Configure Git
93 - echo "Configuring Git..."
94 - git config core.quotepath false
95 build:
96 commands:
97 - echo "Building site..."
98 - hugo build --gc --minify
99 artifacts:
100 baseDirectory: public
101 files:
102 - '**/*'
103 cache:
104 paths:
105 - ${HUGO_CACHEDIR}/**/*
106 - ${NPM_CONFIG_CACHE}/**/*
107 ```
108
109 Step 3
110 : Commit and push the change to your GitHub repository.
111
112 ```sh
113 git add -A
114 git commit -m "Create amplify.yml"
115 git push
116 ```
117
118 Step 4
119 : Log in to your AWS account, navigate to the [Amplify Console], then press the **Deploy an app** button.
120
121 Step 5
122 : Choose a source code provider, then press the **Next** button.
123
124 ![screen capture](amplify-step-05.png)
125
126 Step 6
127 : Authorize AWS Amplify to access your GitHub account.
128
129 ![screen capture](amplify-step-06.png)
130
131 Step 7
132 : Select your personal account or relevant organization.
133
134 ![screen capture](amplify-step-07.png)
135
136 Step 8
137 : Authorize access to one or more repositories.
138
139 ![screen capture](amplify-step-08.png)
140
141 Step 9
142 : Select a repository and branch, then press the **Next** button.
143
144 ![screen capture](amplify-step-09.png)
145
146 Step 10
147 : 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.
148
149 Step 11
150 : On the "Review" page, scroll to the bottom then press the **Save and deploy** button.
151
152 Step 12
153 : When your site has finished deploying, press the **Visit deployed URL** button to view your published site.
154
155 ![screen capture](amplify-step-11.png)
156
157 [Amplify Console]: https://console.aws.amazon.com/amplify/apps