본문 바로가기

Programming/Javascript

AWS Amplify로 Astro 배포하기

반응형

 

 

Astro 프로젝트와 AWS 계정이 있다면 쉽게 서비스를 호스팅 할 수 있습니다.

Astro 프로젝트 만들기

yarn create astro@latest my-astro-app

한 줄로 손 쉽게 Astro 프로젝트를 생성할 수 있습니다.

도구가 다 도와줍니다.

생성된 프로젝트에 astro-aws-amplify를 설치해줍니다.

astro-aws-amplify는 Server-side Astro를 amplify로 배포할 수 있게 도와주는 어댑터입니다.

# Using Yarn
yarn add astro-aws-amplify

Astro Config에 어댑터를 추가해줍니다.

// astro.config.mjs
import { defineConfig } from "astro/config";
import awsAmplify from "astro-aws-amplify"; // 추가

export default defineConfig({
    output: "server", // 추가
    adapter: awsAmplify(), // 추가
});

Astro 프로젝트의 준비는 끝났습니다.

Amplify에 앱 호스팅하기

  1. Amplify 콘솔에서 새 앱 생성을 선택합니다.
  2. 앱 생성 단계 중 앱 설정 단계 중 프론트엔드 빌드 명령을 수정하여야 합니다.

빌드 설정에서 YML 파일 편집을 선택합니다.

  1. 다음과 같이 편집합니다.
version: 1
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - env >> .env
        - yarn 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/**/*
  1. Amplify 앱 생성을 완료합니다.

Amplify에 빌드 실패 시

2025-03-12T05:57:00.082Z [WARNING]: warning astro@5.4.3: The engine "pnpm" appears to be invalid.

2025-03-12T05:57:00.087Z [WARNING]: error yocto-spinner@0.2.1: The engine "node" is incompatible with this module. Expected version ">=18.19". Got "18.18.2"

2025-03-12T05:57:00.093Z [WARNING]: error Found incompatible module.

2025-03-12T05:57:00.094Z [INFO]: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

2025-03-12T05:57:00.171Z [ERROR]: !!! Build failed

2025-03-12T05:57:00.171Z [ERROR]: !!! Error: Command failed with exit code 1

만약 빌드 시 다음과 같은 에러때문에 실패한다면 node의 버전이 맞지 않아 발생한 문제입니다.

해결방법

  1. node의 버전을 맞춰주시면 됩니다.
  2. 빌드 설정의 YML 파일을 다음과 같이 변경해줍니다.
- yarn install

>> 변경

- yarn install --ignore-engines

참고

반응형