Skip to content

Setup

Astro AWS Amplify is an Astro adapter for deploying server-side Astro sites on AWS Amplify Hosting.

Prerequisites

  • an Astro site - v4.x or higher (may also work on v3.x sites)

Installation

Terminal window
npm install 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()
})

Configuration

Astro

Server and hybrid modes are supported. For static sites, remove the adapter and follow these instructions.

AWS Amplify

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:

Amplify Environment Variables
_CUSTOM_IMAGE=amplify:al2023

Build specifications

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:
- env >> .env
- npm run build
- mv node_modules ./.amplify-hosting/compute/default
- mv .env ./.amplify-hosting/compute/default/.env
artifacts:
baseDirectory: .amplify-hosting
files:
- '**/*'
cache:
paths:
- node_modules/**/*

Further reading