Created
July 3, 2018 07:17
-
-
Save navjotdhanawat/92f8683ddfc5bf99c6bd47ce6dedaa4e to your computer and use it in GitHub Desktop.
Create json and upload to s3 bucket using nodejs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var AWS = require('aws-sdk'); | |
AWS.config.update({ region: 'us-east-1' }); | |
var s3 = new AWS.S3(); | |
var obj = { | |
firstname: "Navjot", | |
lastname: "Dhanawat" | |
}; | |
var buf = Buffer.from(JSON.stringify(obj)); | |
var data = { | |
Bucket: 'bucket-name', | |
Key: 'filename.json', | |
Body: buf, | |
ContentEncoding: 'base64', | |
ContentType: 'application/json', | |
ACL: 'public-read' | |
}; | |
s3.upload(data, function (err, data) { | |
if (err) { | |
console.log(err); | |
console.log('Error uploading data: ', data); | |
} else { | |
console.log('succesfully uploaded!!!'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks brother