> ## Documentation Index
> Fetch the complete documentation index at: https://docs.springwinter.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy React and FastAPI on AWS

> Deploy a React static frontend and FastAPI container API with explicit build settings, exact CORS origins, health checks and versioned local tests.

Deploy React as a static website and FastAPI as a web server when the browser and API are separate processes. SpringWinter serves the frontend through S3 and CloudFront and runs the API container behind the project load balancer. This guide uses the reviewed v0.1.0 template, which has no database.

## Suitability and prerequisites

Choose this layout for a Vite-style static frontend calling an HTTP API. If the frontend needs request-time server rendering, use a web server for that process. Review [compatibility](https://docs.springwinter.dev/reference/compatibility.md).

You need Node 24, Python 3.13 with uv for the example, a GitHub repository, a SpringWinter account and a verified AWS connection. A container build also needs Docker. Keep the npm and uv lockfiles. The [tagged source](https://github.com/SpringWinter-Research/templates/tree/v0.1.0/react-fastapi) is a starter, not a production-authenticated service.

## Architecture

```mermaid theme={null}
flowchart LR
    Operator[Dashboard or coding agent] --> Control[SpringWinter control plane]
    Control -->|Approved deployment| AWS
    Browser[Browser] --> CDN
    Browser -->|HTTPS API call| ALB
    subgraph AWS[Customer-owned AWS account]
        CDN[CloudFront and private S3 frontend]
        ALB[Application load balancer]
        API[FastAPI Fargate tasks]
        ALB --> API
    end
```

The browser calls a public API. CORS controls browser access by origin; it does not replace API authentication. The sample allows GET requests from configured origins only.

## Run the example locally

```bash theme={null}
git clone --branch v0.1.0 --depth 1 \
  https://github.com/SpringWinter-Research/templates.git springwinter-templates
cd springwinter-templates/react-fastapi
npm ci
npm test
npm run build
cd backend
uv sync --frozen
uv run python -m unittest
uv run uvicorn main:app --host 0.0.0.0 --port 8000
```

In another terminal, from the frontend directory:

```bash theme={null}
VITE_API_URL=http://localhost:8000 npm run dev
```

The backend defaults to the local frontend origin `http://localhost:5173`. `GET /health` returns `{"status":"ok"}`. `GET http://localhost:8000/api/message` returns `{"message":"Hello from FastAPI"}`. The tests use application test clients and no database. Verify the greeting in the browser as well as through HTTP.

Build the backend image from the frontend directory:

```bash theme={null}
docker build -f backend/Dockerfile -t springwinter-fastapi backend
```

The Dockerfile installs the locked uv dependencies, runs as an unprivileged user and launches `.venv/bin/uvicorn main:app --host 0.0.0.0 --port 8000`. See [FastAPI's Docker guidance](https://fastapi.tiangolo.com/deployment/docker/).

## Configure dashboard resources

Copy the template into its own repository for the simplest path. If you keep the public monorepo layout, prefix these paths with `react-fastapi/`.

| Resource | Setting | Value in the copied template repository |
| - | - | - |
| API web server | Dockerfile path | `backend/Dockerfile` |
| API web server | Root directory/build context | `backend` |
| API web server | Port and health path | `8000`, `/health` |
| API runtime | `CORS_ORIGINS` | Exact final frontend HTTPS origin. |
| Static website | Build command | `npm ci && npm run build` |
| Static website | Output directory | `dist` |
| Static build | `VITE_API_URL` | Returned backend HTTPS origin. |

The Dockerfile path is relative to the repository root. The context is a separate setting. Deploy the API, use its returned URL for the frontend build, then set CORS to the actual frontend origin. Use managed URLs first. Update the allowlist when a custom frontend hostname is ready.

Do not enable wildcard CORS as a troubleshooting shortcut. `VITE_API_URL` is public configuration; no credentials belong in it. Changing it requires a new frontend build. Runtime backend variables are separate.

## Deploy with an agent or REST client

Use the [Codex, Claude Code or Cursor skill](https://docs.springwinter.dev/guides/coding-agents.md) and ask for both resources in one approved plan. Confirm Region, costs and public exposure before provisioning. For API automation, read [Static websites](https://docs.springwinter.dev/api-reference/static-websites.md) and [Web servers](https://docs.springwinter.dev/api-reference/web-servers.md) from the current contract. Do not send a container port to a static website.

## Verification and troubleshooting

Observe each exact workflow. Open the frontend HTTPS URL and confirm the greeting, refresh a nested route if your app has one, and check the API separately. A passing `/health` endpoint does not test browser CORS or `VITE_API_URL`.

| Symptom | Check |
| - | - |
| Frontend tries its own origin for `/api/message` | Was `VITE_API_URL` present during the build? Rebuild after correcting it. |
| API works with curl but not the browser | Exact origin, protocol and CORS headers. |
| API unhealthy | Uvicorn bind address, port and health path. |
| Docker cannot find `pyproject.toml` | Build context must be `backend`, independent of Dockerfile location. |

## Production, costs and cleanup

Add authentication, request validation, rate limits and monitoring before customer use. A database requires a separate resource and verified connection; this example does not test one. Use [cost estimation](https://docs.springwinter.dev/guides/cost-estimation.md) for static requests/transfer, compute, load balancing, builds and logs, plus separate platform fees.

For a temporary test, approve deletion of both resources and their previews. Verify retained AWS artifacts and charges. No AWS deployment success is claimed by the local tests or published container-build evidence.

## Questions

**Can React call private PostgreSQL directly?** No. Add an authenticated backend and keep database credentials server-side.

**Does a new API URL update an old frontend build?** No. Rebuild the static frontend with the new public URL.

Related: [full-stack applications](https://docs.springwinter.dev/guides/full-stack-apps.md), [environment variables](https://docs.springwinter.dev/concepts/environment-variables.md), [deployment troubleshooting](https://docs.springwinter.dev/troubleshooting/deployments.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.