gpt4 book ai didi

node.js - AWS node.js 没有创建 S3 存储桶?

转载 作者:太空宇宙 更新时间:2023-11-03 23:44:37 26 4
gpt4 key购买 nike

我正在尝试使用基本教程来创建 S3 存储桶,如下所示

var AWS = require('aws-sdk');

AWS.config.loadFromPath('./myawsconfig.json');
AWS.config.update({region: 'eu-west-1'});

var s3 = new AWS.S3();
s3.client.createBucket({Bucket: 'pBucket'}, function() {
var data = {Bucket: 'pBucket', Key: 'myKey', Body: 'Hello!'};
s3.client.putObject(data, function(err, data) {
if (err) {
console.log("Error uploading data: ", err);
} else {
console.log("Successfully uploaded data to myBucket/myKey");
}
});
});

但是我收到以下错误

node createbucket.js
Error uploading data: { [NoSuchBucket: The specified bucket does not exist]
message: 'The specified bucket does not exist',
code: 'NoSuchBucket',
name: 'NoSuchBucket',
statusCode: 404,
retryable: false }

最佳答案

我刚刚遇到了这个问题,显然 Node.js 教程代码无法编译。我得到一个 var 对象没有 createBucket 方法。

这有效:

var AWS = require('aws-sdk');
AWS.config.loadFromPath('./credentials.json');
// Set your region for future requests.
AWS.config.update({region: 'us-east-1'});
// Create a bucket and put something in it.
var s3 = new AWS.S3();
s3.client.createBucket({Bucket: 'hackathon-test'}, function() {
var data = {Bucket: 'hackathon-test', Key: 'myKey', Body: 'Hello!'};
s3.client.putObject(data, function(err, data) {
if (err) {
console.log("Error uploading data: ", err);
} else {
console.log("Successfully uploaded data to myBucket/myKey");
}
});
});

关于node.js - AWS node.js 没有创建 S3 存储桶?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15975467/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com