Copyright © 2026 Rusty Nations. Released under MIT License.
A demonstration Single Page Application for the AWS SPA Hosting Kit. This React + Vite + TypeScript SPA demonstrates the complete CI/CD workflow from GitHub to AWS.
This example SPA serves as:
- Reference Implementation: Shows how to structure a SPA for AWS hosting
- Testing Tool: Validates that the hosting kit and CodePipeline work correctly
- Starting Point: Can be forked and customized for your own projects
- Documentation: Illustrates recommended directory structure and best practices
- Framework: React 19
- Build Tool: Vite 7
- Language: TypeScript
- Package Manager: npm
sample-spa/
├── src/ # Source code
│ ├── App.tsx # Main application component
│ ├── main.tsx # Application entry point
│ ├── index.css # Global styles
│ └── assets/ # Images, fonts, etc.
├── public/ # Static assets (copied as-is)
├── dist/ # Build output (generated by 'npm run build')
├── buildspec.yml # AWS CodeBuild build specification
├── package.json # Dependencies and scripts
├── vite.config.ts # Vite configuration
└── tsconfig.json # TypeScript configuration
This SPA follows a recommended structure for React applications:
your-spa/
├── src/ # Application source code
│ ├── components/ # Reusable React components
│ ├── pages/ # Page components (for routing)
│ ├── hooks/ # Custom React hooks
│ ├── utils/ # Utility functions
│ ├── services/ # API service layer
│ ├── types/ # TypeScript type definitions
│ ├── assets/ # Images, fonts, icons
│ └── App.tsx # Main application component
├── public/ # Static assets
├── tests/ # Test files
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ └── e2e/ # End-to-end tests
├── buildspec.yml # AWS CodeBuild specification
├── package.json # Dependencies and scripts
└── README.md # Project documentation
# Install dependencies
npm install
# Start development server
npm run dev
# Open browser to http://localhost:5173# Build the application
npm run build
# Output directory: dist/
# Files are optimized and minified for productionThis SPA is designed to be deployed via the AWS SPA Hosting Kit:
- Configure the hosting kit: Point it to this repository in
config.yml - Deploy infrastructure: Run
npm run deployin the hosting kit - Authorize connection: Complete GitHub OAuth in AWS Console
- Trigger pipeline: Push code or manually trigger
- CloudFront serves: SPA is accessible globally via CloudFront URL
Timeline: 5-10 minutes from commit to live
This example SPA includes placeholder comments indicating where you would add:
See src/App.tsx for examples of:
- Fetching data from REST APIs
- Integrating with API Gateway
- Handling API responses and errors
See src/App.tsx for examples of:
- AWS Cognito integration with Amplify
- Sign-in/sign-out flows
- Protected routes
See src/App.tsx for examples of:
- Redux setup and usage
- Zustand setup and usage
- Context API patterns
# Run linter
npm run lint
# Build and preview
npm run build
npm run previewVite outputs to dist/ by default. This matches the hosting kit default configuration.
To add environment variables:
-
Development: Create
.env.localfileVITE_API_URL=https://dev-api.example.com -
Production: Configure in hosting kit
config.ymlbuild: environmentVariables: VITE_API_URL: 'https://api.example.com'
-
Access in code:
const apiUrl = import.meta.env.VITE_API_URL;
When adapting this for your own SPA:
- Update dependencies: Add your required packages
- Update build command: Modify if using different build script
- Update output directory: Configure in hosting kit if different from
dist/ - Add environment variables: Configure in hosting kit
config.yml - Add custom build steps: Update
buildspec.ymlif needed - Add tests: Include test execution in
buildspec.yml
For questions about this example or the AWS SPA Hosting Kit, open an issue on GitHub:
- Example SPA: https://github.com/rusty428/aws-spa-react-example
- Hosting Kit: https://github.com/rusty428/aws-spa-hosting-kit