Skip to content

Commit f057116

Browse files
Add AWS App Runner deployment configuration - single-container setup with PHP+Nginx, automated deployment scripts, and comprehensive documentation
1 parent 9610f5c commit f057116

File tree

9 files changed

+1201
-0
lines changed

9 files changed

+1201
-0
lines changed

AWS-APPRUNNER-DEPLOYMENT.md

Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
# AWS App Runner Deployment Guide
2+
3+
This guide walks you through deploying your Food Influencer Marketplace to AWS App Runner, the easiest serverless container deployment option on AWS.
4+
5+
## 🚀 Quick Start
6+
7+
1. **Configure your GitHub repository URL** in `deploy-apprunner.sh`
8+
2. **Update Instagram API credentials** in `apprunner.yaml`
9+
3. **Run the deployment script**: `./deploy-apprunner.sh`
10+
11+
## 📋 Prerequisites
12+
13+
### AWS Account Setup
14+
15+
- AWS Account with appropriate permissions
16+
- AWS CLI installed and configured
17+
- Docker installed locally (for testing)
18+
19+
### GitHub Repository
20+
21+
- Your code pushed to a GitHub repository
22+
- Repository must be public OR you need to set up GitHub connection in AWS
23+
24+
### Instagram API Setup (Optional)
25+
26+
- Meta Developer Account
27+
- Instagram App ID and Secret
28+
- Valid redirect URI configured
29+
30+
## 🔧 Configuration Steps
31+
32+
### 1. Install AWS CLI
33+
34+
**macOS:**
35+
36+
```bash
37+
brew install awscli
38+
```
39+
40+
**Linux:**
41+
42+
```bash
43+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
44+
unzip awscliv2.zip
45+
sudo ./aws/install
46+
```
47+
48+
**Windows:**
49+
Download and install from [AWS CLI installer](https://awscli.amazonaws.com/AWSCLIV2.msi)
50+
51+
### 2. Configure AWS CLI
52+
53+
```bash
54+
aws configure
55+
```
56+
57+
You'll need:
58+
59+
- **AWS Access Key ID**
60+
- **AWS Secret Access Key**
61+
- **Default region** (recommend: `us-east-1`)
62+
- **Default output format** (recommend: `json`)
63+
64+
### 3. Update Configuration Files
65+
66+
#### A. Edit `deploy-apprunner.sh`
67+
68+
```bash
69+
# Set your GitHub repository URL
70+
GITHUB_REPO_URL="https://github.com/yourusername/ourawork.git"
71+
```
72+
73+
#### B. Edit `apprunner.yaml`
74+
75+
Update the Instagram API credentials:
76+
77+
```yaml
78+
- name: INSTAGRAM_APP_ID
79+
value: YOUR_ACTUAL_INSTAGRAM_APP_ID
80+
- name: INSTAGRAM_APP_SECRET
81+
value: YOUR_ACTUAL_INSTAGRAM_APP_SECRET
82+
- name: INSTAGRAM_REDIRECT_URI
83+
value: https://YOUR_DOMAIN/instagram_auth.php
84+
```
85+
86+
### 4. Make Deployment Script Executable
87+
88+
```bash
89+
chmod +x deploy-apprunner.sh
90+
```
91+
92+
## 🚀 Deployment Process
93+
94+
### Automated Deployment
95+
96+
Run the deployment script:
97+
98+
```bash
99+
./deploy-apprunner.sh
100+
```
101+
102+
The script will:
103+
104+
1. ✅ Check AWS CLI configuration
105+
2. ✅ Create necessary IAM roles
106+
3. ✅ Test database connectivity
107+
4. ✅ Build and test Docker image locally
108+
5. ✅ Deploy to AWS App Runner
109+
6. ✅ Show deployment status
110+
111+
### Manual Deployment (Alternative)
112+
113+
If you prefer manual deployment:
114+
115+
1. **Push your code to GitHub**
116+
2. **Go to AWS App Runner Console**
117+
3. **Create Service:**
118+
- Source: Repository
119+
- Connect to GitHub
120+
- Select your repository
121+
- Branch: main
122+
- Configuration: Use configuration file (`apprunner.yaml`)
123+
124+
## 🏗 Architecture Overview
125+
126+
```
127+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
128+
│ User Browser │───▶│ AWS App Runner │───▶│ AWS RDS │
129+
│ │ │ │ │ (MariaDB) │
130+
└─────────────────┘ │ - Nginx │ └─────────────────┘
131+
│ - PHP-FPM │
132+
│ - Your App │ ┌─────────────────┐
133+
└─────────────────┘───▶│ Instagram API │
134+
└─────────────────┘
135+
```
136+
137+
## 📊 Cost Estimation
138+
139+
**AWS App Runner:**
140+
141+
- CPU: 0.25 vCPU = ~$5-10/month
142+
- Memory: 0.5 GB = ~$2-5/month
143+
- Requests: Pay per million requests (~$0.40/million)
144+
145+
**Existing RDS:** Already configured and running
146+
147+
**Total Estimated Cost:** ~$10-20/month for low to moderate traffic
148+
149+
## 🔍 Monitoring & Management
150+
151+
### Check Service Status
152+
153+
```bash
154+
aws apprunner list-services --region us-east-1
155+
```
156+
157+
### View Service Details
158+
159+
```bash
160+
aws apprunner describe-service --service-arn YOUR_SERVICE_ARN
161+
```
162+
163+
### View Logs
164+
165+
- Go to AWS App Runner Console
166+
- Select your service
167+
- Click on "Logs" tab
168+
- View Application logs and System logs
169+
170+
### Health Check
171+
172+
Your app includes a health check endpoint at `/health` that returns:
173+
174+
```
175+
healthy
176+
```
177+
178+
## 🔒 Security Features
179+
180+
- **HTTPS by default** - App Runner provides SSL/TLS automatically
181+
- **Security headers** - Configured in nginx
182+
- **Environment variables** - Sensitive data stored securely
183+
- **Private networking** - Database access through AWS network
184+
- **File access restrictions** - Sensitive files blocked
185+
186+
## 🛠 Troubleshooting
187+
188+
### Common Issues
189+
190+
#### 1. Database Connection Failed
191+
192+
```bash
193+
# Test database connectivity
194+
docker run --rm php:8.4-cli php -r "
195+
try {
196+
\$pdo = new PDO('mysql:host=ourawork.ckb40aqwiavq.us-east-1.rds.amazonaws.com;dbname=marketplace', 'admin', 'family95');
197+
echo 'Connection successful!';
198+
} catch (Exception \$e) {
199+
echo 'Error: ' . \$e->getMessage();
200+
}
201+
"
202+
```
203+
204+
#### 2. Service Build Failed
205+
206+
- Check your Dockerfile syntax
207+
- Ensure all required files are in the repository
208+
- Check App Runner logs in AWS Console
209+
210+
#### 3. Health Check Failed
211+
212+
- Verify nginx configuration
213+
- Check if application starts correctly
214+
- Review application logs
215+
216+
#### 4. Instagram API Issues
217+
218+
- Verify App ID and Secret are correct
219+
- Ensure redirect URI matches exactly
220+
- Check that your domain is properly configured
221+
222+
### Debug Commands
223+
224+
**Check service status:**
225+
226+
```bash
227+
aws apprunner describe-service --service-arn arn:aws:apprunner:us-east-1:ACCOUNT:service/ourawork-marketplace
228+
```
229+
230+
**List all services:**
231+
232+
```bash
233+
aws apprunner list-services
234+
```
235+
236+
**Check logs:**
237+
238+
- AWS Console > App Runner > Your Service > Logs
239+
240+
## 🔄 Updates & Maintenance
241+
242+
### Automatic Deployments
243+
244+
App Runner automatically redeploys when you push to the main branch of your connected GitHub repository.
245+
246+
### Manual Deployments
247+
248+
```bash
249+
aws apprunner start-deployment --service-arn YOUR_SERVICE_ARN
250+
```
251+
252+
### Environment Variable Updates
253+
254+
Update in AWS Console:
255+
256+
1. Go to App Runner service
257+
2. Click "Configuration" tab
258+
3. Edit "Environment variables"
259+
4. Save (triggers automatic redeployment)
260+
261+
## 📈 Scaling
262+
263+
App Runner automatically scales based on traffic:
264+
265+
- **Minimum instances:** 1
266+
- **Maximum instances:** 25 (configurable)
267+
- **Concurrent requests per instance:** 100
268+
269+
To modify scaling:
270+
271+
```bash
272+
aws apprunner update-service --service-arn YOUR_SERVICE_ARN --auto-scaling-configuration-arn YOUR_CONFIG_ARN
273+
```
274+
275+
## 🔧 Advanced Configuration
276+
277+
### Custom Domain Setup
278+
279+
1. **Add custom domain in App Runner Console**
280+
2. **Update DNS records** with provided values
281+
3. **SSL certificate** automatically provisioned
282+
283+
### VPC Configuration
284+
285+
For private database access:
286+
287+
```bash
288+
aws apprunner create-vpc-connector --vpc-connector-name ourawork-connector
289+
```
290+
291+
### Environment-Specific Deployments
292+
293+
Create separate services for staging/production:
294+
295+
- `ourawork-marketplace-staging`
296+
- `ourawork-marketplace-production`
297+
298+
## 📞 Support
299+
300+
If you encounter issues:
301+
302+
1. **Check AWS App Runner documentation**
303+
2. **Review CloudWatch logs**
304+
3. **Test locally using Docker**
305+
4. **Verify database connectivity**
306+
5. **Check Instagram API configuration**
307+
308+
## 🎯 Next Steps
309+
310+
After successful deployment:
311+
312+
1. **Set up custom domain**
313+
2. **Configure monitoring/alerts**
314+
3. **Set up staging environment**
315+
4. **Configure backup strategies**
316+
5. **Implement CI/CD pipeline**
317+
318+
---
319+
320+
**🎉 Congratulations!** Your Food Influencer Marketplace is now running on AWS App Runner!

0 commit comments

Comments
 (0)