Skip to content

Add AWS Amplify build config and frontend deployment instructions#47

Merged
csecrestjr merged 1 commit into
mainfrom
copilot/fix-b5e22784-c3b6-4baf-ab2a-756757dee339
Aug 29, 2025
Merged

Add AWS Amplify build config and frontend deployment instructions#47
csecrestjr merged 1 commit into
mainfrom
copilot/fix-b5e22784-c3b6-4baf-ab2a-756757dee339

Conversation

Copilot AI commented Aug 29, 2025

Copy link
Copy Markdown

This PR adds AWS Amplify hosting configuration and comprehensive deployment documentation to enable automatic frontend builds and deployments when pushing to the main branch.

What's Added

1. amplify.yml - Build Configuration

  • Configures Amplify to run npm ci and npm run build from the frontend directory
  • Publishes frontend/build as deployment artifacts
  • Caches frontend/node_modules for faster subsequent builds

2. frontend/DEPLOYMENT.md - Step-by-Step Guide

Comprehensive documentation covering:

  • Prerequisites and repository setup
  • Amplify Console connection instructions
  • Environment variable configuration
  • Custom domain and HTTPS setup
  • SPA routing configuration with rewrite rules
  • Troubleshooting common build and deployment issues

Technical Implementation

To make the Amplify configuration work with the existing frontend structure:

  1. Created build wrapper: Added frontend/package.json that orchestrates the build process by:

    • Installing dependencies in the chat-ui subdirectory
    • Running the Vite build process
    • Copying the output from chat-ui/dist/ to frontend/build/ (as expected by Amplify)
  2. Fixed build issues: Resolved JSX compilation errors by:

    • Renaming store.js to store.jsx to properly handle JSX syntax
    • Updating all import statements to reference the correct file extension
  3. Added package-lock.json files: Generated lockfiles for both frontend/ and frontend/chat-ui/ directories to support npm ci for faster, deterministic builds

  4. Configured .gitignore: Excludes build artifacts (build/, dist/) and dependencies (node_modules/) from version control

Testing

The build process has been validated to work correctly:

cd frontend
npm ci
npm run build
# Results in frontend/build/ containing the deployable React app

This configuration enables seamless integration with AWS Amplify Console for automated deployments on every push to main.

This pull request was created as a result of the following prompt from Copilot chat.

Add an Amplify build configuration and deployment instructions for the frontend so the project can be connected to AWS Amplify Console and auto-deploy on pushes to main. Create two files:

  1. amplify.yml at repository root with build steps that run from the frontend directory and publish frontend/build as artifacts.

  2. frontend/DEPLOYMENT.md with step-by-step Amplify setup instructions, environment variable notes, and troubleshooting tips.

Files to add (exact contents):

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - cd frontend
        - npm ci
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: frontend/build
    files:
      - '**/*'
  cache:
    paths:
      - frontend/node_modules/**/*
```markdown
# Deploying the Fruitful frontend with AWS Amplify

This document explains how to connect this repository to AWS Amplify Hosting so the frontend auto-builds and deploys from the `main` branch.

Prerequisites
- AWS account with permissions to use Amplify Console.
- The repo `NTARI-OpenCoreLab/Fruitful` (this repository).
- The frontend build output directory is `frontend/build` (the amplify.yml below uses this).

What this PR adds
- `amplify.yml` at the repository root configured to run `npm ci` and `npm run build` inside the `frontend` folder and publish `frontend/build` as the artifact.

Steps to connect in Amplify Console
1. Open the Amplify Console in the AWS Management Console.
2. Click "Host web app" → "Connect app" → choose GitHub and authorize if necessary.
3. Select repository `NTARI-OpenCoreLab/Fruitful` and the `main` branch.
4. Amplify will detect a build specification. If it does not, upload or point to the `amplify.yml` file added to the repo.
5. Review the build settings: the build will run the `preBuild` steps which `cd` into `frontend` and run `npm ci`, then `npm run build`. Artifacts are taken from `frontend/build`.
6. Save and deploy. Amplify will provision resources and start the first build.

Environment variables
- If your frontend requires runtime environment variables (e.g., API endpoints, feature flags), add them under "App settings → Environment variables" in Amplify. Use the same names your app expects (e.g., REACT_APP_API_URL). Re-deploy after adding or changing env vars.

Custom domain and HTTPS
- Add a custom domain in Amplify under "Domain management" and follow the steps. Amplify will create and validate an ACM certificate and add DNS records in Route53 if you choose.

Rewrites & redirects (SPA routing)
- For single-page apps, ensure Amplify has a rewrite rule:
  Source address: </*>
  Target address: /index.html
  Type: 200 (Rewrite)

Troubleshooting
- Build failures: check Amplify build logs. Common issues are missing install dependencies or incorrect build script name in `package.json`.
- Wrong artifact dir: ensure `frontend/build` exists after running `npm run build` locally.
- Environment vars not applied: verify names and redeploy.

Tips
- Use hashed filenames for static assets so Amplify/CDN can cache them aggressively.
- Keep secrets out of repo; use Amplify environment variables or AWS Secrets Manager.

``` 

Please create a branch from main, add these two files, and open a pull request titled "Add AWS Amplify build config and frontend deployment instructions". The PR should target the main branch. No assignees necessary.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@csecrestjr
csecrestjr marked this pull request as ready for review August 29, 2025 23:38
@csecrestjr
csecrestjr merged commit d5a7d76 into main Aug 29, 2025
1 check passed
Copilot AI changed the title [WIP] Add AWS Amplify build config and frontend deployment instructions Add AWS Amplify build config and frontend deployment instructions Aug 29, 2025
Copilot AI requested a review from csecrestjr August 29, 2025 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants