A simple, non-technical web application that allows users to control EC2 instances using natural language prompts. The app sends prompts to an existing API (API Gateway → Lambda AgentProxy → Bedrock Agent) and displays the agent's responses.
- Natural Language Control: Send prompts like "Start the dev-server instance" or "Stop the dev-server instance"
- Quick Actions: Pre-filled buttons for common operations
- API Configuration: Configurable API URL and optional API key with localStorage persistence
- Session History: View all previous conversations (newest first)
- Error Handling: Comprehensive error messages for network and API issues
- Keyboard Shortcuts: Use Cmd/Ctrl + Enter to submit prompts
- Responsive Design: Works on desktop and mobile devices
- React 19 with TypeScript
- Vite for fast development and building
- Tailwind CSS for styling
- Fetch API for HTTP requests
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Open your browser: Navigate to the URL shown in the terminal (typically
http://localhost:5173)
-
Configure API: The default API URL is pre-filled. Optionally add an API key if required.
-
Send Prompts:
- Type your prompt in the textarea
- Use quick action buttons for common operations
- Press "Send" or use Cmd/Ctrl + Enter
-
View Responses: The agent's response will appear in the response panel
-
Check History: All conversations are saved in the session history (resets on page refresh)
- Default API URL:
https://ef2fwq22il.execute-api.us-east-1.amazonaws.com/test/chat - Request Format:
POSTwith{"prompt": "<text>"}body - Response Format:
{"answer": "<text>"} - Optional Header:
x-api-keyfor authentication
- Start dev-server: Fills prompt with "Start the dev-server instance"
- Stop dev-server: Fills prompt with "Stop the dev-server instance"
If you encounter CORS errors:
- Check that the API URL is correct
- Verify the API has CORS enabled for your domain
- Check browser DevTools Network tab for preflight request failures
- Ensure you have a stable internet connection
- Check if the API endpoint is accessible
- Verify API key if authentication is required
- The API key is stored in localStorage under
ec2_prompt_api_key - Clear browser data to reset stored API key
- Check DevTools Application tab to verify localStorage
npm run buildThe built files will be in the dist/ directory, ready for deployment to S3/CloudFront.
src/
├── components/
│ ├── ApiConfigBar.tsx # API URL and key configuration
│ ├── PromptBox.tsx # Prompt input and quick actions
│ ├── ResponsePanel.tsx # Response display and error handling
│ └── HistoryList.tsx # Session history display
├── lib/
│ ├── api.ts # API wrapper and localStorage utilities
│ └── types.ts # TypeScript interfaces
├── App.tsx # Main application component
├── main.tsx # Application entry point
└── index.css # Tailwind CSS and custom styles
- ✅ Page loads with API URL prefilled
- ✅ Quick action buttons fill textarea with correct prompts
- ✅ Send button triggers POST to API and displays answer
- ✅ Cmd/Ctrl + Enter submits prompts
- ✅ Error handling shows readable messages
- ✅ History panel shows prompt/answer pairs (newest first)
- ✅ API key persistence in localStorage
- ✅ Clean, simple UI for non-technical users
If you plan to make this repository public and host the app from it, review and apply the following:
-
Protect your backend
- Require an API key on API Gateway. Do not allow unauthenticated access.
- Set CORS to only allow your domains (e.g.,
http://localhost:5173for dev and your production origin). Avoid*. - Enable rate limiting/throttling and consider AWS WAF with IP allowlists/managed rules.
- Monitor and rotate API keys if they may have leaked (a public repo implies higher exposure).
-
Default API URL exposure
- This repo ships with a default public API URL in
src/lib/api.ts(DEFAULT_API_URL). If your backend allows anonymous requests, anyone can hit it from their own browser. - Recommendation: keep API key required, restrict CORS, or replace the default with a placeholder before making the repo public.
- This repo ships with a default public API URL in
-
API key handling in the browser
- The app stores the key in
localStorageunderec2_prompt_api_keyfor convenience. This is fine for simple demos, but note:- Any XSS could exfiltrate the key. Keep dependencies updated and avoid injecting untrusted HTML.
- Prefer a strict Content‑Security‑Policy (CSP) and avoid third‑party scripts when hosting.
- For production-grade security, avoid long‑lived keys in the browser; use short‑lived tokens or a tiny proxy backend.
- The app stores the key in
-
HTTPS and security headers
- Serve via HTTPS (CloudFront/other CDN). Enable HSTS.
- Add response headers at the CDN:
Content-Security-Policy(lock downscript-src,connect-srcto your API URL)Referrer-Policy: no-referrerX-Content-Type-Options: nosniffX-Frame-Options: DENY- Proper
Cache-Control(e.g.,no-cacheforindex.html,immutablefor hashed assets)
-
Operational hygiene
- Do not commit secrets. Keep
.env*files out of git (already ignored by default patterns). - Watch dependency updates (Dependabot/Renovate).
- Monitor CloudWatch logs and set alerts for unusual traffic or failures.
- Do not commit secrets. Keep
If someone clones this repo to use with their own backend, they should update:
-
API endpoint (prefill value)
- File:
src/lib/api.ts - Change
DEFAULT_API_URLto your own API Gateway URL.
- File:
-
Quick action texts (instance name)
- File:
src/components/PromptBox.tsx - Update the two strings:
"Start the dev-server instance""Stop the dev-server instance"
- Replace
dev-serverwith your instance label.
- File:
-
CORS allowlist (backend setting)
- Add your dev origin (e.g.,
http://localhost:5173) and your deployed origin in API Gateway CORS settings.
- Add your dev origin (e.g.,
-
API key (optional)
- If your API requires a key, enter it in the UI. It is stored under
localStoragekeyec2_prompt_api_key. - Do not hardcode keys in the repo.
- If your API requires a key, enter it in the UI. It is stored under
-
Optional branding
- File:
index.html→ page title and favicon
- File:
After changes:
npm install
npm run dev
# open the printed localhost URLTroubleshooting: use browser DevTools → Network to inspect preflight/POST requests and verify CORS/headers.