Deploy Astro to AWS Amplify
How to deploy your Astro Server-Side Rendered (SSR) websites to AWS Amplify.
How to deploy your Astro Server-Side Rendered (SSR) websites to AWS Amplify.
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.
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$99One-time license · Lifetime updates
You’ll need the following:
Let’s get started by creating a new Astro project. Open your terminal and run the following command:
npm create astro@latest my-appnpm create astro is the recommended way to scaffold an Astro project quickly.
When prompted, choose:
Empty when prompted on how to start the new project.Yes when prompted if you plan to write TypeScript.Strict when prompted how strict TypeScript should be.Yes when prompted to install dependencies.Yes when prompted to initialize a git repository.Once that’s done, you can move into the project directory and start the app:
cd my-appnpm run devThe 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:
npm install dotenvThe libraries installed include:
dotenv: A library for handling environment variables.Before deploying your Astro project, you need to install the astro-aws-amplify adapter. This is easily done via the Astro CLI:
npm install astro-aws-amplifyThe libraries installed include:
astro-aws-amplify: An adapter that prepares Astro websites to be deployed on AWS Amplify.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:
import { defineConfig } from 'astro/config';import awsAmplify from 'astro-aws-amplify';
export default defineConfig({ output: "server", adapter: awsAmplify(),});The additions do the following:
astro-aws-amplify.adapter of your Astro application.output to server to enable server-side rendering compatible output.Then, create an amplify.yml at the root of the repository with the following code:
version: 1frontend: 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:
preBuild commands to install the dependencies of your Astro project.build commands to:
.env file at the root of the project.node_modules directory and .env file to Amplify’s compute directory.The code is now ready to deploy to AWS Amplify. Use the following steps to deploy:
Start by creating a GitHub repository containing your app’s code.
Then, navigate to the AWS Amplify Dashboard and click on Get Started under the Host your web app section.
.env file, and PORT as 3000. Click Next to proceed.
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.
How Astro 7.2 incremental static builds cut a one-post rebuild from ~16.5s to ~10s, restoring 637 of 661 pages from cache with the right cacheKey setup.
We're excited to announce that MailKite email support is now available in all LaunchFast starter kits. Send transactional emails through MailKite with a single environment variable change.
Hydration is expensive. A practical look at Astro islands: the cheaper options to exhaust first (static HTML, build-time data, server islands, progressive enhancement), and the cases where hydration is useful.