Quick Start Guide
This guide walks you through the basics of installing and using @aws/nx-plugin to rapidly build projects on AWS.
Prerequisites
Section titled “Prerequisites”The following global dependencies are needed before proceeding:
Required
Section titled “Required”- Git
- Node >= 22 (We recommend using something like NVM to manage your node versions)
- verify by running
node --version
- verify by running
- UV >= 0.5.29
- install Python 3.14 by running:
uv python install 3.14.0 - verify with
uv python list --only-installed
- install Python 3.14 by running:
Recommended
Section titled “Recommended”- PNPM >= 11 (you can also use Yarn >= 4, Bun >= 1, or NPM >= 10 if you prefer)
- verify by running
pnpm --version,yarn --version,bun --versionornpm --version
- verify by running
- AWS Credentials configured to your target AWS account are required to deploy your application (as well as for some local development workflows).
- Docker or Finch >= 1.6.0 is required for some generators. For Docker, multi-platform builds must be set up; Finch supports multi-platform builds out of the box.
- Terraform >= 1.12 is required if you choose to use this for infrastructure as code instead of CDK
- verify by running
terraform --version
- verify by running
- If you are using VSCode, we recommend installing the Nx Console VSCode Plugin.
Step 1: Initialize a New Nx Workspace
Section titled “Step 1: Initialize a New Nx Workspace”Run the following command to create an Nx workspace with the package manager of your choice:
pnpm create @aws/nx-workspace my-projectyarn create @aws/nx-workspace my-projectnpm create @aws/nx-workspace -- my-projectbun create @aws/nx-workspace my-projectOnce complete, navigate to the project directory:
cd my-projectStep 2: Use Generators to Scaffold your Project
Section titled “Step 2: Use Generators to Scaffold your Project”We’ll add a tRPC API, React Website, Cognito Authentication, and CDK or Terraform Infrastructure in this quick-start guide. Depending on the type of project you’re building, you can choose any combination of generators to quickly bootstrap your project. Check out the Generators in the navigation bar to the left to see the full list of options, or try the graph builder to construct your workspace visually.
As a shortcut, you can use the button below to copy the commands to scaffold the full application.
Otherwise, follow the steps below to run each generator yourself.
Add a tRPC API
Section titled “Add a tRPC API”pnpm nx g @aws/nx-plugin:ts#api --name=demo-api --framework=trpc --auth=iam --no-interactiveyarn nx g @aws/nx-plugin:ts#api --name=demo-api --framework=trpc --auth=iam --no-interactivenpx nx g @aws/nx-plugin:ts#api --name=demo-api --framework=trpc --auth=iam --no-interactivebunx nx g @aws/nx-plugin:ts#api --name=demo-api --framework=trpc --auth=iam --no-interactiveYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:ts#api --name=demo-api --framework=trpc --auth=iam --no-interactive --dry-runyarn nx g @aws/nx-plugin:ts#api --name=demo-api --framework=trpc --auth=iam --no-interactive --dry-runnpx nx g @aws/nx-plugin:ts#api --name=demo-api --framework=trpc --auth=iam --no-interactive --dry-runbunx nx g @aws/nx-plugin:ts#api --name=demo-api --framework=trpc --auth=iam --no-interactive --dry-run- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - ts#api - Fill in the required parameters
- name: demo-api
- framework: trpc
- auth: iam
- Click
Generate
This will create the API inside the packages/demo-api folder.
Add a React Website
Section titled “Add a React Website”pnpm nx g @aws/nx-plugin:ts#website --name=demo-website --no-interactiveyarn nx g @aws/nx-plugin:ts#website --name=demo-website --no-interactivenpx nx g @aws/nx-plugin:ts#website --name=demo-website --no-interactivebunx nx g @aws/nx-plugin:ts#website --name=demo-website --no-interactiveYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:ts#website --name=demo-website --no-interactive --dry-runyarn nx g @aws/nx-plugin:ts#website --name=demo-website --no-interactive --dry-runnpx nx g @aws/nx-plugin:ts#website --name=demo-website --no-interactive --dry-runbunx nx g @aws/nx-plugin:ts#website --name=demo-website --no-interactive --dry-run- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - ts#website - Fill in the required parameters
- name: demo-website
- Click
Generate
This scaffolds a new React website in packages/demo-website.
Add Cognito Authentication
Section titled “Add Cognito Authentication”pnpm nx g @aws/nx-plugin:ts#website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --no-interactiveyarn nx g @aws/nx-plugin:ts#website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --no-interactivenpx nx g @aws/nx-plugin:ts#website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --no-interactivebunx nx g @aws/nx-plugin:ts#website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --no-interactiveYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:ts#website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --no-interactive --dry-runyarn nx g @aws/nx-plugin:ts#website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --no-interactive --dry-runnpx nx g @aws/nx-plugin:ts#website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --no-interactive --dry-runbunx nx g @aws/nx-plugin:ts#website#auth --project=@my-project/demo-website --cognitoDomain=my-demo --no-interactive --dry-run- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - ts#website#auth - Fill in the required parameters
- project: @my-project/demo-website
- cognitoDomain: my-demo
- Click
Generate
This sets up the necessary infrastructure and React code to add Cognito Authentication to your website.
Connect Frontend to Backend
Section titled “Connect Frontend to Backend”pnpm nx g @aws/nx-plugin:connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --no-interactiveyarn nx g @aws/nx-plugin:connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --no-interactivenpx nx g @aws/nx-plugin:connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --no-interactivebunx nx g @aws/nx-plugin:connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --no-interactiveYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --no-interactive --dry-runyarn nx g @aws/nx-plugin:connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --no-interactive --dry-runnpx nx g @aws/nx-plugin:connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --no-interactive --dry-runbunx nx g @aws/nx-plugin:connection --sourceProject=@my-project/demo-website --targetProject=@my-project/demo-api --no-interactive --dry-run- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - connection - Fill in the required parameters
- sourceProject: @my-project/demo-website
- targetProject: @my-project/demo-api
- Click
Generate
This configures the necessary providers to ensure your website can call your tRPC API.
Add Infrastructure
Section titled “Add Infrastructure”Add the infrastructure project based on your chosen IAC provider.
pnpm nx g @aws/nx-plugin:ts#infra --name=infra --no-interactiveyarn nx g @aws/nx-plugin:ts#infra --name=infra --no-interactivenpx nx g @aws/nx-plugin:ts#infra --name=infra --no-interactivebunx nx g @aws/nx-plugin:ts#infra --name=infra --no-interactiveYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:ts#infra --name=infra --no-interactive --dry-runyarn nx g @aws/nx-plugin:ts#infra --name=infra --no-interactive --dry-runnpx nx g @aws/nx-plugin:ts#infra --name=infra --no-interactive --dry-runbunx nx g @aws/nx-plugin:ts#infra --name=infra --no-interactive --dry-run- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - ts#infra - Fill in the required parameters
- name: infra
- Click
Generate
This configures a CDK App which you can use to deploy your infrastructure on AWS.
pnpm nx g @aws/nx-plugin:terraform#project --name=infra --no-interactiveyarn nx g @aws/nx-plugin:terraform#project --name=infra --no-interactivenpx nx g @aws/nx-plugin:terraform#project --name=infra --no-interactivebunx nx g @aws/nx-plugin:terraform#project --name=infra --no-interactiveYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:terraform#project --name=infra --no-interactive --dry-runyarn nx g @aws/nx-plugin:terraform#project --name=infra --no-interactive --dry-runnpx nx g @aws/nx-plugin:terraform#project --name=infra --no-interactive --dry-runbunx nx g @aws/nx-plugin:terraform#project --name=infra --no-interactive --dry-run- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - terraform#project - Fill in the required parameters
- name: infra
- Click
Generate
This configures a Terraform project which you can use to deploy your infrastructure on AWS.
Step 3: Run your Website and API Locally
Section titled “Step 3: Run your Website and API Locally”Use the following command to start local dev servers for your website and its connected APIs:
pnpm devyarn devnpm run devbun devYour website will be available at http://localhost:4200.
Changes to both your website and API will be reflected in real-time as both the local website and API servers will hot-reload.
Step 4: Define Cloud Resources and Deploy to AWS
Section titled “Step 4: Define Cloud Resources and Deploy to AWS”Open packages/infra/src/stacks/application-stack.ts and add the following code:
import { Stack, StackProps } from 'aws-cdk-lib';import { DemoApi, DemoWebsite, UserIdentity } from '@my-project/common-constructs';import { Construct } from 'constructs';
export class ApplicationStack extends Stack { constructor(scope: Construct, id: string, props?: 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'); }}This is all the CDK we need to write to deploy our full stack application.
Open packages/infra/src/main.tf and add the following code:
# Include metrics tracking for @aws/nx-plugin usagemodule "metrics" { source = "../../common/terraform/src/metrics"}
# Deploy user identitymodule "user_identity" { source = "../../common/terraform/src/core/user-identity"}
# Shared asset bucket — stages Lambda deployment zips for every lambda / API modulemodule "asset_bucket" { source = "../../common/terraform/src/core/asset-bucket"}
# Deploy APImodule "demo_api" { source = "../../common/terraform/src/app/apis/demo-api"
asset_bucket_name = module.asset_bucket.bucket_name}
# Grant authenticated users access to invoke the APIresource "aws_iam_policy" "api_invoke_policy" { name = "DemoApiInvokePolicy" description = "Policy to allow authenticated users to invoke the 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}
# Deploy websiteprovider "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]}This is all the Terraform we need to write to deploy our full stack application.
Build and Deploy the Infrastructure
Section titled “Build and Deploy the Infrastructure”Next, run the following command to build your project:
pnpm buildyarn buildnpm run buildbun buildBootstrap your infrastructure:
pnpm nx bootstrap infrayarn nx bootstrap infranpx nx bootstrap infrabunx nx bootstrap infrapnpm nx bootstrap infrayarn nx bootstrap infranpx nx bootstrap infrabunx nx bootstrap infraDeploy your project:
pnpm nx deploy-sandbox infrayarn nx deploy-sandbox infranpx nx deploy-sandbox infrabunx nx deploy-sandbox infrapnpm nx apply infrayarn nx apply infranpx nx apply infrabunx nx apply infraStep 5: Test the Website with Deployed Cloud Resources
Section titled “Step 5: Test the Website with Deployed Cloud Resources”-
Fetch the
runtime-config.jsonfile:Terminal window pnpm nx load-runtime-config demo-websiteTerminal window yarn nx load-runtime-config demo-websiteTerminal window npx nx load-runtime-config demo-websiteTerminal window bunx nx load-runtime-config demo-website -
Start the local website server
Terminal window pnpm nx serve demo-websiteTerminal window yarn nx serve demo-websiteTerminal window npx nx serve demo-websiteTerminal window bunx nx serve demo-website
Your website will be available at http://localhost:4200, and will point to the resources you deployed for the API and authentication.
Congratulations! 🎉 You have successfully built and deployed a full-stack application using @aws/nx-plugin!