trypost/cdk/README.md

68 lines
1.9 KiB
Markdown
Raw Normal View History

# Trypost Media AWS CDK Stack
This CDK stack sets up the AWS cloud infrastructure for media asset hosting for Trypost:
1. **S3 Bucket (`trypostmedia`)**:
- Secure private bucket with `BlockPublicAccess.BLOCK_ALL` and `BucketEncryption.S3_MANAGED`
- Configured CORS headers for web uploads and downloads
- SSL enforced (`enforceSSL: true`)
2. **CloudFront Distribution**:
- Integrated with S3 using modern **Origin Access Control (OAC)**
- HTTPS redirect policy
- Optimized caching policy and CORS security response headers
- Generates the CloudFront URL for distribution
3. **CloudFormation Outputs**:
- `BucketName`: Name of the S3 bucket (`trypostmedia`)
- `DistributionDomainName` & `DistributionUrl`: CloudFront CDN endpoint to use in `.env` (`AWS_URL`)
---
## Deployment Instructions
### 1. Install Dependencies
Navigate to this directory and install dependencies:
```bash
cd cdk
npm install
```
### 2. Configure AWS Credentials
Ensure your AWS credentials and region are configured:
```bash
export AWS_ACCESS_KEY_ID="<your-access-key-id>"
export AWS_SECRET_ACCESS_KEY="<your-secret-access-key>"
export AWS_DEFAULT_REGION="ap-south-2"
```
### 3. Synthesize and Review CloudFormation Template
```bash
npx cdk synth
```
### 4. Deploy Stack
```bash
npx cdk deploy
```
## Deployed Stack Details (ap-south-2)
- **Bucket ARN**: `arn:aws:s3:::trypostmedia`
- **Bucket Name**: `trypostmedia`
- **Distribution ID**: `E1R40XT0UHR7NK`
- **Distribution Domain**: `d28qhqo5myc2wf.cloudfront.net`
- **Distribution URL**: `https://d28qhqo5myc2wf.cloudfront.net`
---
## Laravel `.env` Configuration
Configure your Laravel `.env` with the deployed outputs:
```env
FILESYSTEM_DISK=s3
AWS_ACCESS_KEY_ID=<your-iam-access-key>
AWS_SECRET_ACCESS_KEY=<your-iam-secret-key>
AWS_DEFAULT_REGION=ap-south-2
AWS_BUCKET=trypostmedia
AWS_URL=https://d28qhqo5myc2wf.cloudfront.net
```