Astro AWS Amplify is an Astro adapter for deploying server-side Astro sites on AWS Amplify Hosting.
- an Astro site -
v4.x
or higher (may also work onv3.x
sites)
# Using NPM
npm install astro-aws-amplify
# Using Yarn
yarn add astro-aws-amplify
# Using PNPM
pnpm add astro-aws-amplify
In your Astro config, add the adapter:
// astro.config.mjs
import { defineConfig } from 'astro/config';
+ import awsAmplify from 'astro-aws-amplify';
export default defineConfig({
+ output: 'server', // output: 'hybrid'
+ adapter: awsAmplify()
})
Server and hybrid modes are supported. For static sites, remove the adapter and follow these instructions.
AWS Amplify Hosting uses Node.js v16 by default which isn't supported.
You can use the newer Amazon Linux:2023
by adding an environment variable of:
_CUSTOM_IMAGE=amplify:al2023
You can use the following build specifications as-is or customize it to your liking. Moving the node_modules
folder is required for npm
and Yarn
deployments.
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
- mv node_modules ./.amplify-hosting/compute/default
artifacts:
baseDirectory: .amplify-hosting
files:
- '**/*'
cache:
paths:
- node_modules/**/*
version: 1
frontend:
phases:
preBuild:
commands:
- npm i -g pnpm
- pnpm config set store-dir .pnpm-store
- pnpm i
build:
commands:
- pnpm run build
artifacts:
baseDirectory: .amplify-hosting
files:
- '**/*'
cache:
paths:
- .pnpm-store/**/*
version: 1
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- yarn run build
- mv node_modules ./.amplify-hosting/compute/default
artifacts:
baseDirectory: .amplify-hosting
files:
- '**/*'
cache:
paths:
- node_modules/**/*
- server and hybrid mode
- image optimization with
<Image>
and<Picture />
- base paths
- middleware
- Amplify Image optimization
- build previews (
npm run preview
) - ???
Custom 404 pages (like 404.astro
) need to be server-side rendered (not prerendered) to work. This is a limitation with Amplify.
Due to limitations with Amplify routing, to serve public
files without extensions, place them in a folder called assets
(/public/assets/
) and reference them with /assets/filename
:
somefile
Any other static files with extensions will work as usual.
MIT
Uses code from the @astrojs/node adapter to establish a Node.js server required for AWS Amplify SSR environments.