Testing aws3 in node.js.
var AWS = require('aws-sdk');
AWS.config.region = 'ap-northeast-1';
AWS.config.endpoint = 'archabucket.s3-website-ap-northeast-1.amazonaws.com';
var fs = require('fs');
var s3 = new AWS.S3();
var params = {
Bucket: 'archabucket',
Key: 'logo.png',
ACL: 'public-read ',
Body: fs.createReadStream('94.png'),
ContentType: 'image/png'
};
s3.putObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
I was simply testing while looking at the life coding, but an endpoint error popped up, so I caught the endpoint, and this time I saw a Networking Error: connect ECONNREFUSED error.
I can simply return the bucket list... You have given Amazon S3FullAccess privileges. Even if I change the area to Seoul, it's the same and it's very difficult.
aws node.js
AWS.config.region = 'ap-northeast-1';
AWS.config.endpoint = 'archabucket.s3-website-ap-northeast-1.amazonaws.com';
I think this is the problem. The region and endpoint of Seoul should be specified as follows (ap-northeast-1 is Japan, and Seoul should be 2).)
AWS.config.region = 'ap-northeast-2';
AWS.config.endpoint = 's3.ap-northeast-2.amazonaws.com';
I modified the code on Aws Node.js SDK page and the data is uploaded.
Refer to here for the part annotated with added in the code below.
var AWS = require('aws-sdk');
//Added Part-Start
AWS.config.update({
signatureVersion: 'v4'
});
//Added Part-End
var s3 = new AWS.S3();
s3.createBucket({Bucket: 'Bucketname'}, function() {
var parameters = {Bucket: 'Bucket name', Key: 'myKey', Body: 'Hello!'};
s3.putObject(params, function(err, data) {
if (err)
console.log(err)
else console.log("Successfully uploaded data to myBucket/myKey");
});
});
© 2024 OneMinuteCode. All rights reserved.