빠른 시작 가이드
이 가이드는 AWS에서 프로젝트를 빠르게 구축하기 위해 @aws/nx-plugin을 설치하고 사용하는 기본 방법을 설명합니다.
필수 조건
섹션 제목: “필수 조건”진행 전 다음 전역 의존성이 필요합니다:
- Git
- Node >= 22 (NVM 같은 도구로 Node 버전 관리 권장)
node --version실행하여 버전 확인
- PNPM >= 10 (선호한다면 Yarn >= 4, Bun >= 1, NPM >= 10 사용 가능)
pnpm --version,yarn --version,bun --version또는npm --version실행하여 버전 확인
- UV >= 0.5.29
uv python install 3.12.0실행하여 Python 3.12 설치uv python list --only-installed실행하여 확인
- 애플리케이션을 배포할 대상 AWS 계정에 구성된 AWS Credentials
권장 사항
섹션 제목: “권장 사항”- 일부 생성기에는 Docker가 필요합니다
- CDK 대신 인프라스트럭처 코드로 Terraform을 사용할 경우 Terraform >= 1.12 설치 필요
terraform --version명령어로 버전 확인
- VSCode 사용 시 Nx Console VSCode Plugin 설치 권장
1단계: 새 Nx 워크스페이스 초기화
섹션 제목: “1단계: 새 Nx 워크스페이스 초기화”원하는 패키지 매니저로 Nx 워크스페이스를 생성하려면 다음 명령어를 실행하세요:
npx create-nx-workspace@21.6.5 my-project --pm=pnpm --preset=@aws/nx-plugin --ci=skip --aiAgentsnpx create-nx-workspace@21.6.5 my-project --pm=yarn --preset=@aws/nx-plugin --ci=skip --aiAgentsnpx create-nx-workspace@21.6.5 my-project --pm=npm --preset=@aws/nx-plugin --ci=skip --aiAgentsnpx create-nx-workspace@21.6.5 my-project --pm=bun --preset=@aws/nx-plugin --ci=skip --aiAgents완료 후 프로젝트 디렉토리로 이동합니다:
cd my-project2단계: 생성기를 사용하여 프로젝트 스캐폴딩
섹션 제목: “2단계: 생성기를 사용하여 프로젝트 스캐폴딩”이 빠른 시작 가이드에서는 tRPC API, React 웹사이트, Cognito 인증 및 CDK/Terraform 인프라를 추가합니다. 프로젝트 유형에 따라 원하는 생성기 조합을 선택하여 빠르게 프로젝트를 부트스트랩할 수 있습니다. 왼쪽 네비게이션 바의 가이드 에서 전체 옵션 목록을 확인하세요.
tRPC API 추가
섹션 제목: “tRPC API 추가”- 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
- VSCode에서 Nx 콘솔 열기
- 클릭
Generate (UI)"Common Nx Commands" 섹션에서 - 검색
@aws/nx-plugin - ts#trpc-api - 필수 매개변수 입력
- name: demo-api
- auth: IAM
- 클릭
Generate
pnpm nx g @aws/nx-plugin:ts#trpc-api --name=demo-api --auth=IAMyarn nx g @aws/nx-plugin:ts#trpc-api --name=demo-api --auth=IAMnpx nx g @aws/nx-plugin:ts#trpc-api --name=demo-api --auth=IAMbunx nx g @aws/nx-plugin:ts#trpc-api --name=demo-api --auth=IAM어떤 파일이 변경될지 확인하기 위해 드라이 런을 수행할 수도 있습니다
pnpm nx g @aws/nx-plugin:ts#trpc-api --name=demo-api --auth=IAM --dry-runyarn nx g @aws/nx-plugin:ts#trpc-api --name=demo-api --auth=IAM --dry-runnpx nx g @aws/nx-plugin:ts#trpc-api --name=demo-api --auth=IAM --dry-runbunx nx g @aws/nx-plugin:ts#trpc-api --name=demo-api --auth=IAM --dry-run이 명령은 packages/demo-api 폴더 내에 API를 생성합니다.
React 웹사이트 추가
섹션 제목: “React 웹사이트 추가”- 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
- VSCode에서 Nx 콘솔 열기
- 클릭
Generate (UI)"Common Nx Commands" 섹션에서 - 검색
@aws/nx-plugin - ts#react-website - 필수 매개변수 입력
- name: demo-website
- 클릭
Generate
pnpm nx g @aws/nx-plugin:ts#react-website --name=demo-websiteyarn nx g @aws/nx-plugin:ts#react-website --name=demo-websitenpx nx g @aws/nx-plugin:ts#react-website --name=demo-websitebunx nx g @aws/nx-plugin:ts#react-website --name=demo-website어떤 파일이 변경될지 확인하기 위해 드라이 런을 수행할 수도 있습니다
pnpm nx g @aws/nx-plugin:ts#react-website --name=demo-website --dry-runyarn nx g @aws/nx-plugin:ts#react-website --name=demo-website --dry-runnpx nx g @aws/nx-plugin:ts#react-website --name=demo-website --dry-runbunx nx g @aws/nx-plugin:ts#react-website --name=demo-website --dry-run이 명령은 packages/demo-website에 새 React 웹사이트를 스캐폴딩합니다.
Cognito 인증 추가
섹션 제목: “Cognito 인증 추가”- 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
- VSCode에서 Nx 콘솔 열기
- 클릭
Generate (UI)"Common Nx Commands" 섹션에서 - 검색
@aws/nx-plugin - ts#react-website#auth - 필수 매개변수 입력
- project: @my-project/demo-website
- cognitoDomain: my-demo
- 클릭
Generate
pnpm nx g @aws/nx-plugin:ts#react-website#auth --project=@my-project/demo-website --cognitoDomain=my-demoyarn nx g @aws/nx-plugin:ts#react-website#auth --project=@my-project/demo-website --cognitoDomain=my-demonpx nx g @aws/nx-plugin:ts#react-website#auth --project=@my-project/demo-website --cognitoDomain=my-demobunx nx g @aws/nx-plugin:ts#react-website#auth --project=@my-project/demo-website --cognitoDomain=my-demo어떤 파일이 변경될지 확인하기 위해 드라이 런을 수행할 수도 있습니다
pnpm nx g @aws/nx-plugin:ts#react-website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --dry-runyarn nx g @aws/nx-plugin:ts#react-website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --dry-runnpx nx g @aws/nx-plugin:ts#react-website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --dry-runbunx nx g @aws/nx-plugin:ts#react-website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --dry-run이 명령은 웹사이트에 Cognito 인증을 추가하기 위한 인프라와 React 코드를 설정합니다.
프론트엔드-백엔드 연결
섹션 제목: “프론트엔드-백엔드 연결”- 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
- VSCode에서 Nx 콘솔 열기
- 클릭
Generate (UI)"Common Nx Commands" 섹션에서 - 검색
@aws/nx-plugin - api-connection - 필수 매개변수 입력
- sourceProject: @my-project/demo-website
- targetProject: @my-project/demo-api
- 클릭
Generate
pnpm nx g @aws/nx-plugin:api-connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-apiyarn nx g @aws/nx-plugin:api-connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-apinpx nx g @aws/nx-plugin:api-connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-apibunx nx g @aws/nx-plugin:api-connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api어떤 파일이 변경될지 확인하기 위해 드라이 런을 수행할 수도 있습니다
pnpm nx g @aws/nx-plugin:api-connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --dry-runyarn nx g @aws/nx-plugin:api-connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --dry-runnpx nx g @aws/nx-plugin:api-connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --dry-runbunx nx g @aws/nx-plugin:api-connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --dry-run이 명령은 웹사이트가 tRPC API를 호출할 수 있도록 필요한 프로바이더를 구성합니다.
인프라 추가
섹션 제목: “인프라 추가”선택한 IaC 제공자에 따라 인프라 프로젝트를 추가합니다.
- 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
- VSCode에서 Nx 콘솔 열기
- 클릭
Generate (UI)"Common Nx Commands" 섹션에서 - 검색
@aws/nx-plugin - ts#infra - 필수 매개변수 입력
- name: infra
- 클릭
Generate
pnpm nx g @aws/nx-plugin:ts#infra --name=infrayarn nx g @aws/nx-plugin:ts#infra --name=infranpx nx g @aws/nx-plugin:ts#infra --name=infrabunx nx g @aws/nx-plugin:ts#infra --name=infra어떤 파일이 변경될지 확인하기 위해 드라이 런을 수행할 수도 있습니다
pnpm nx g @aws/nx-plugin:ts#infra --name=infra --dry-runyarn nx g @aws/nx-plugin:ts#infra --name=infra --dry-runnpx nx g @aws/nx-plugin:ts#infra --name=infra --dry-runbunx nx g @aws/nx-plugin:ts#infra --name=infra --dry-run이 명령은 AWS에 인프라를 배포하는 데 사용할 CDK 앱을 구성합니다.
- 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
- VSCode에서 Nx 콘솔 열기
- 클릭
Generate (UI)"Common Nx Commands" 섹션에서 - 검색
@aws/nx-plugin - terraform#project - 필수 매개변수 입력
- name: infra
- 클릭
Generate
pnpm nx g @aws/nx-plugin:terraform#project --name=infrayarn nx g @aws/nx-plugin:terraform#project --name=infranpx nx g @aws/nx-plugin:terraform#project --name=infrabunx nx g @aws/nx-plugin:terraform#project --name=infra어떤 파일이 변경될지 확인하기 위해 드라이 런을 수행할 수도 있습니다
pnpm nx g @aws/nx-plugin:terraform#project --name=infra --dry-runyarn nx g @aws/nx-plugin:terraform#project --name=infra --dry-runnpx nx g @aws/nx-plugin:terraform#project --name=infra --dry-runbunx nx g @aws/nx-plugin:terraform#project --name=infra --dry-run이 명령은 AWS에 인프라를 배포하는 데 사용할 Terraform 프로젝트를 구성합니다.
3단계: 로컬에서 웹사이트 및 API 실행
섹션 제목: “3단계: 로컬에서 웹사이트 및 API 실행”다음 명령어로 웹사이트와 연결된 API의 로컬 개발 서버를 시작합니다:
pnpm nx run demo-website:serve-localyarn nx run demo-website:serve-localnpx nx run demo-website:serve-localbunx nx run demo-website:serve-local웹사이트는 http://localhost:4200에서 확인할 수 있습니다.
웹사이트와 API의 변경 사항은 실시간으로 반영되며, 두 서버 모두 핫 리로드됩니다.
4단계: 클라우드 리소스 정의 및 AWS 배포
섹션 제목: “4단계: 클라우드 리소스 정의 및 AWS 배포”packages/infra/src/stacks/application-stack.ts를 열고 다음 코드를 추가하세요:
import * as cdk from 'aws-cdk-lib';import { DemoApi, DemoWebsite, UserIdentity } from ':my-project/common-constructs';import { Construct } from 'constructs';
export class ApplicationStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props);
const identity = new UserIdentity(this, 'identity'); const api = new DemoApi(this, 'api', { integrations: DemoApi.defaultIntegrations(this).build(), }); api.grantInvokeAccess(identity.identityPool.authenticatedRole);
new DemoWebsite(this, 'website'); }}이 코드는 풀스택 애플리케이션 배포에 필요한 모든 CDK 구성을 포함합니다.
packages/infra/src/main.tf를 열고 다음 코드를 추가하세요:
# @aws/nx-plugin 사용 메트릭 추적 포함module "metrics" { source = "../../common/terraform/src/metrics"}
# 사용자 신원 배포module "user_identity" { source = "../../common/terraform/src/core/user-identity"}
# API 배포module "demo_api" { source = "../../common/terraform/src/app/apis/demo-api"}
# 인증된 사용자의 API 호출 권한 부여resource "aws_iam_policy" "api_invoke_policy" { name = "DemoApiInvokePolicy" description = "인증된 사용자가 API를 호출할 수 있도록 하는 정책"
policy = jsonencode({ Version = "2012-10-17" Statement = [ { Effect = "Allow" Action = "execute-api:Invoke" Resource = "${module.demo_api.api_execution_arn}/*/*" } ] })}
resource "aws_iam_role_policy_attachment" "authenticated_api_access" { role = module.user_identity.authenticated_role_name policy_arn = aws_iam_policy.api_invoke_policy.arn}
# 웹사이트 배포provider "aws" { alias = "us_east_1" region = "us-east-1"}
module "demo_website" { source = "../../common/terraform/src/app/static-websites/demo-website"
providers = { aws.us_east_1 = aws.us_east_1 }
depends_on = [module.user_identity, module.demo_api]}이 코드는 풀스택 애플리케이션 배포에 필요한 모든 Terraform 구성을 포함합니다.
인프라 빌드 및 배포
섹션 제목: “인프라 빌드 및 배포”프로젝트를 빌드하려면 다음 명령어를 실행하세요:
pnpm nx run-many --target build --allyarn nx run-many --target build --allnpx nx run-many --target build --allbunx nx run-many --target build --all인프라를 부트스트랩합니다:
pnpm nx run infra:bootstrapyarn nx run infra:bootstrapnpx nx run infra:bootstrapbunx nx run infra:bootstrappnpm nx run infra:bootstrapyarn nx run infra:bootstrapnpx nx run infra:bootstrapbunx nx run infra:bootstrap프로젝트를 배포합니다:
pnpm nx run infra:deploy my-project-sandbox/*yarn nx run infra:deploy my-project-sandbox/*npx nx run infra:deploy my-project-sandbox/*bunx nx run infra:deploy my-project-sandbox/*pnpm nx run infra:applyyarn nx run infra:applynpx nx run infra:applybunx nx run infra:apply5단계: 배포된 클라우드 리소스로 웹사이트 테스트
섹션 제목: “5단계: 배포된 클라우드 리소스로 웹사이트 테스트”-
runtime-config.json파일 가져오기:Terminal window pnpm nx run demo-website:load:runtime-configTerminal window yarn nx run demo-website:load:runtime-configTerminal window npx nx run demo-website:load:runtime-configTerminal window bunx nx run demo-website:load:runtime-config -
로컬 웹사이트 서버 시작
Terminal window pnpm nx run demo-website:serveTerminal window yarn nx run demo-website:serveTerminal window npx nx run demo-website:serveTerminal window bunx nx run demo-website:serve
웹사이트는 http://localhost:4200에서 확인할 수 있으며, 배포된 API 및 인증 리소스를 가리킵니다.
축하합니다! 🎉 @aws/nx-plugin을 사용하여 풀스택 애플리케이션을 성공적으로 구축하고 배포했습니다!