AWS에서 MongoDB, Cloudinary, Render를 통합 구현하는 방법
Yelp Camp 프로젝트에서 MongoDB(데이터베이스), Cloudinary(이미지 저장), Render(앱 배포)를 사용하고 있다면, AWS에서 이 모든 기능을 통합하여 운영할 수 있습니다. 본 글에서는 AWS에서 각 서비스를 대체하는 방법과 코드 예제를 설명합니다.
✅ 1. MongoDB → AWS의 대체 서비스
📌 Amazon DocumentDB (with MongoDB compatibility)
MongoDB와 호환되는 AWS의 NoSQL 데이터베이스 서비스입니다.
1) 기존 MongoDB 코드 예제
const mongoose = require('mongoose');
mongoose.connect('mongodb+srv://username:password@cluster.mongodb.net/myDatabase', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
2) AWS DocumentDB로 변경 시
const mongoose = require('mongoose');
mongoose.connect('mongodb://username:password@docdb-instance-endpoint:27017/myDatabase?ssl=true&replicaSet=rs0', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
⚠️ DocumentDB는 완벽한 MongoDB 호환이 아니므로 일부 기능이 제한될 수 있습니다.
💡 추천 옵션: MongoDB Atlas를 AWS에서 사용하거나 DocumentDB를 활용
✅ 2. Cloudinary → AWS의 대체 서비스
📌 Amazon S3 (Simple Storage Service)
Cloudinary의 이미지 저장 및 최적화 기능을 S3와 Lambda를 활용하여 구현할 수 있습니다.
1) 기존 Cloudinary 코드
const cloudinary = require('cloudinary').v2;
cloudinary.config({
cloud_name: 'your_cloud_name',
api_key: 'your_api_key',
api_secret: 'your_api_secret'
});
cloudinary.uploader.upload('image.jpg', (error, result) => {
console.log(result);
});
2) AWS S3 업로드 코드 (Node.js)
const AWS = require('aws-sdk');
const fs = require('fs');
const s3 = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: 'us-east-1'
});
const uploadFile = async () => {
const fileContent = fs.readFileSync('image.jpg');
const params = {
Bucket: 'your-s3-bucket',
Key: 'image.jpg',
Body: fileContent,
ContentType: 'image/jpeg'
};
await s3.upload(params).promise();
console.log('File uploaded successfully');
};
uploadFile();
💡 추천 옵션: Amazon S3 + Lambda를 활용하여 자동 이미지 최적화 구현
✅ 3. Render → AWS의 대체 서비스
📌 AWS Elastic Beanstalk (Node.js 백엔드 배포)
Render에서 배포한 백엔드를 AWS Elastic Beanstalk을 사용하여 배포할 수 있습니다.
1) 기존 Render 배포 스크립트
{
"scripts": {
"start": "node server.js"
}
}
2) AWS Elastic Beanstalk 배포 (Node.js)
# AWS Elastic Beanstalk CLI 설치
pip install awsebcli --upgrade --user
# 앱 초기화 및 배포
eb init -p node.js my-app
eb create my-env
💡 추천 옵션: Elastic Beanstalk 또는 AWS ECS + Fargate
✅ AWS로 통합한 아키텍처 예시
사용자 → AWS CloudFront → AWS Amplify (React 프론트엔드)
→ AWS Elastic Beanstalk (Node.js 백엔드)
→ Amazon DocumentDB (MongoDB)
→ Amazon S3 (이미지 저장)
🚀 결론: AWS로 통합할 수 있지만 고려할 점이 많음!
- 빠르게 배포 & 유지보수 편리함 → Render + Cloudinary + MongoDB Atlas 유지
- AWS 생태계로 완전 이전 → Amazon S3, Elastic Beanstalk, DocumentDB 활용
👉 현재 규모가 크지 않다면 기존 구조를 유지하고, AWS 학습 후 점진적으로 이전하는 것도 좋은 방법입니다! 🚀
Leave a comment