김현기

aws cognito를 이용해 AWS 엑세스 키에 대한 접근 방지 후 S3와 연결

......@@ -3,9 +3,33 @@ var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var AWS = require('aws-sdk');
// 이미지를 저장할 버킷 이름
var bucketName = "kindofyourdog";
// s3 버킷의 엔드 포인트
var bucketRegion = "ap-northeast-2";
// AWS Cognito 인증
var IdentityPoolId = "ap-northeast-2:7cba9a17-588b-40d6-8c70-eb8ba4d573be";
// AWS의 config 정보를 Update해준다 -> 이용자가 S3 버킷에 접근 가능하다
AWS.config.update({
region:bucketRegion,
credentials:new AWS.CognitoIdentityCredentials({
IdentityPoolId:IdentityPoolId
})
})
// 내가 사용할 S3
var s3 = new aws.S3({
apiVersion: "2006-03-01",
params: {Bucket: bucketName}
});
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
// image업로드 시 해당 route기능 사용
var imageUploadRouter = require('./routes/imageUpload');
var app = express();
......@@ -21,6 +45,8 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
//이미지 업로드
app.use('/upload', imageUploadRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
......
const AWS = require('aws-sdk');
const ID = 'id';
const SECRET = 'secret';
const BUCKET_NAME = 'dogpicture-dizzi';
const s3 = new AWS.S3 ({
accessKeyId: ID,
secretAccessKey:SECRET
});
const params = {
Bucket: BUCKET_NAME,
CreateBucketConfiguration: {
//Set your regieon here
LocationConstraint : "us-east-1"
}
};
s3.createBucket(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log('Bucket Created Successfully', data.Location);
});
\ No newline at end of file
......@@ -3,7 +3,11 @@ var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
res.render('index', { title: 'KindOfYourDog' });
});
router.post('/upload', function(req, res, next) {
var name = ""
})
module.exports = router;
......