阅读亚马逊文档,仍然无法做到正确。我在.env
文件中有我的谜题,并想要加载它们(使用名为config
的自定义函数)
import AWS from 'aws-sdk';
const credentials = {
accessKeyId: config('AWSS3AccessKeyID'),
secretAcccessKey: config('AWSS3SecretAccessKey'),
};
AWS.Config.credentials({ ...credentials });
const S3 = new AWS.S3({
computeChecksums: false,
});
export default { S3 };
它说Condif.credetials
不是一个功能。
如何将凭据正确传递给AWS
?
奖励:传递AWS S3
的存储区名称/区域的位置?
答案 0 :(得分:2)
看看这个http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-creating-buckets.html
// Load the SDK for JavaScript
var AWS = require('aws-sdk');
// Load credentials and set region from JSON file
AWS.config.loadFromPath('./config.json');
// Create S3 service object
s3 = new AWS.S3({apiVersion: '2006-03-01'});
// Call S3 to list current buckets
s3.listBuckets(function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Bucket List", data.Buckets);
}
});
非常明显的例子。来自http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-examples.html的更多示例,但我认为您应该阅读aws aws-sdk文档。