我写了这个lambda函数来创建新的s3存储桶。我得到了成功响应,但是没有创建存储桶:
//Creating new s3 bucket
var AWS = require('aws-sdk');
AWS.config.update({
region: '',
accessKeyId: '',
secretAccessKey: ''
});
var s3 = new AWS.S3();
var bucketName = 'sample_bucket';
var keyName = 'sample_text.txt';
exports.handler = function uploadToS3(event, context, callback) {
s3.createBucket({Bucket: bucketName}, function() {
var params = {
Bucket: bucketName,
Key: keyName,
Body: 'Hello World!'
};
s3.putObject(params, function(err, data) {
if (err)
console.log(err);
else
console.log("Successfully uploaded data to " + bucketName);
});
});
callback(null,{ result : 'SUCCESS'});
};
代码中是否有任何问题,或者我是否必须提供一些特殊的访问权限? IAM用户?我向IAM用户提供了编程访问权限。
谢谢!