Deploy Astro to AWS Amplify
LaunchFast LogoLaunchFast
Blog
664 words4 min read

Deploy Astro to AWS Amplify

How to deploy your Astro Server-Side Rendered (SSR) websites to AWS Amplify.

Rishi Raj Jain
Rishi Raj JainAuthor

In this guide, you will learn how to deploy an Astro SSR project to AWS Amplify. You will go through the process of setting up a new Astro project, enabling server-side rendering using the AWS Amplify adapter, and finally deploying it to AWS Amplify.

Sponsored

High Quality Starter Kits with built-in authentication flow (Auth.js), object uploads (AWS, Clouflare R2, Firebase Storage, Supabase Storage), integrated payments (Stripe, LemonSqueezy), email verification flow (Resend, Postmark, Sendgrid), and much more. Compatible with any database (Redis, Postgres, MongoDB, SQLite, Firestore).

Get all 3 kits$147$99

One-time license · Lifetime updates

Table Of Contents

Prerequisites

You’ll need the following:

Create a new Astro application

Let’s get started by creating a new Astro project. Open your terminal and run the following command:

Terminal window
npm create astro@latest my-app

npm create astro is the recommended way to scaffold an Astro project quickly.

When prompted, choose:

Once that’s done, you can move into the project directory and start the app:

Terminal window
cd my-app
npm run dev

The app should be running on localhost:4321.

Next, in your first terminal window, run the command below to install the necessary libraries and packages for building the application:

Terminal window
npm install dotenv

The libraries installed include:

Getting Started with the AWS Amplify Adapter for Astro

Before deploying your Astro project, you need to install the astro-aws-amplify adapter. This is easily done via the Astro CLI:

Terminal window
npm install astro-aws-amplify

The libraries installed include:

Once the adapter is installed, you’ll need to add it to your astro.config.mjs file. Open the file and add the following code:

astro.config.mjs
import { defineConfig } from 'astro/config';
import awsAmplify from 'astro-aws-amplify';
export default defineConfig({
output: "server",
adapter: awsAmplify(),
});

The additions do the following:

Then, create an amplify.yml at the root of the repository with the following code:

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/**/*

The code above does the following:

Deploy to AWS Amplify

The code is now ready to deploy to AWS Amplify. Use the following steps to deploy:

Host your web app in AWS Amplify GitHub as code source in AWS Amplify Link Repo in AWS Amplify Name the project in AWS Amplify Add Environment Variables in AWS Amplify Deploy to AWS Amplify Grab Deployment URL in AWS Amplify

Conclusion

Yay! You now have an Astro project that automatically deploys to AWS Amplify upon Git push.

If you have any questions or comments, feel free to reach out to me on Twitter.

Continue reading