下午好,
我有适用于AWS的默认配置文件,如下所示:
[default]
region = XXXXXX
aws_secret_access_key =XXXXXXXXXXX
ws_access_key_id = XXXXXXXX
我想在初始化aws.s3时覆盖这些配置变量:
let albumName = CONSTANTS.AWS.ALBUM;
let id = CONSTANTS.AWS.KEY;
let bucketRegion = CONSTANTS.AWS.REGION;
let secret = CONSTANTS.AWS.SECRET;
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
secretAccessId: id,
secretAccessKey: secret,
region: bucketRegion,
params: {
Bucket: albumName
}
});
但是我得到的是我使用aws s3 update命令尝试过的旧密钥,但是它不能正常工作。我怎么能覆盖它。 iam使用它通过命令代码将图像上传到相册中:
var albumPhotosKey = encodeURIComponent(albumName) + '//';
var photoKey = albumPhotosKey + name;
var fileStream = fs.createReadStream(req.body.files.path);
fileStream.on('error', function (err) {
if (err) { throw err; }
});
fileStream.on('open', function () {
s3.putObject({
Key: photoKey,
Body: fileStream,
ACL: 'public-read'
}, function (err, data) {
if (err) {
console.log('There was an error uploading your photo: ', err.message);
} else {
console.log('Success', data);
}
});
});
谢谢。
答案 0 :(得分:0)
使用aws cli命令aws configure
。这将提示您输入访问密钥ID,机密,默认区域和输出文件。如果要保留当前值,请按Enter。