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
- PNPM >= 10 (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
- UV >= 0.5.29
- install Python 3.12 by running:
uv python install 3.12.0 - verify with
uv python list --only-installed
- install Python 3.12 by running:
- AWS Credentials configured to your target AWS account (where your application will be deployed)
Recommended
Section titled “Recommended”- Docker is required for some generators.
- 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:
npx create-nx-workspace@21.6.8 my-project --pm=pnpm --preset=@aws/nx-plugin --ci=skip --aiAgentsnpx create-nx-workspace@21.6.8 my-project --pm=yarn --preset=@aws/nx-plugin --ci=skip --aiAgentsnpx create-nx-workspace@21.6.8 my-project --pm=npm --preset=@aws/nx-plugin --ci=skip --aiAgentsnpx create-nx-workspace@21.6.8 my-project --pm=bun --preset=@aws/nx-plugin --ci=skip --aiAgentsOnce 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 Guides in the navigation bar to the left to see the full list of options.
Add a tRPC API
Section titled “Add a tRPC API”- 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#trpc-api - Fill in the required parameters
- name: demo-api
- auth: IAM
- Click
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=IAMYou can also perform a dry-run to see what files would be changed
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-runThis will create the API inside the packages/demo-api folder.
Add a React Website
Section titled “Add a React Website”- 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#react-website - Fill in the required parameters
- name: demo-website
- Click
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-websiteYou can also perform a dry-run to see what files would be changed
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-runThis scaffolds a new React website in packages/demo-website.
Add Cognito Authentication
Section titled “Add Cognito Authentication”- 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#react-website#auth - Fill in the required parameters
- project: @my-project/demo-website
- cognitoDomain: my-demo
- Click
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-demoYou can also perform a dry-run to see what files would be changed
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-runThis 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”- 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 - api-connection - Fill in the required parameters
- sourceProject: @my-project/demo-website
- targetProject: @my-project/demo-api
- Click
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-apiYou can also perform a dry-run to see what files would be changed
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-runThis 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.
- 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
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=infraYou can also perform a dry-run to see what files would be changed
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-runThis configures a CDK App which you can use to deploy your infrastructure on AWS.
- 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
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=infraYou can also perform a dry-run to see what files would be changed
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-runThis 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 nx run demo-website:serve-localyarn nx run demo-website:serve-localnpx nx run demo-website:serve-localbunx nx run demo-website:serve-localYour 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 * 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'); }}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"}
# Deploy APImodule "demo_api" { source = "../../common/terraform/src/app/apis/demo-api"}
# 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 nx run-many --target build --allyarn nx run-many --target build --allnpx nx run-many --target build --allbunx nx run-many --target build --allBootstrap your infrastructure:
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:bootstrapDeploy your project:
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:applyStep 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 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 -
Start the local website server
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
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!