I am trying to perform static website hosting on s3 that has a simple image file, using aws-sdk from my local ide. The code runs without any error and it reflects on my console as well but when i open the endpoint from console it doesn't open the file. The file is in the bucket as well and i have enabled public access. But if i am doing the same through console i mean enabling static website hosting it opens. This is the code...
const aws = require('aws-sdk');
const s3 = new aws.S3();
const fs = require('fs');
const filecon = fs.readFileSync('C:\\Users\\Envy\\Desktop\\murugan.jpeg');
(async function(){
try {
aws.config.setPromisesDependency();
aws.config.update({
region: 'us-east-1'
})
const a1 = await s3.createBucket({Bucket:'ommuruga'}).promise();
const a2 = await s3.upload({Bucket:'ommuruga',Key:'murugan.jpeg',Body:filecon,ACL:'public-read'}).promise();
const a3 = await s3.putBucketWebsite({Bucket:'ommuruga',WebsiteConfiguration:{IndexDocument:{Suffix:'murugan.jpeg'},ErrorDocument:{Key:'Error.html'}}}).promise();
console.log(a3);
}
catch(err){
console.log(`unable to process err: ${err}`);
}
})();
You have to setup permissions for the s3 website to work as explained in AWS docs :
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.