Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const {
S3Client,
CreateBucketCommand,
PutObjectCommand
} = require('@aws-sdk/client-s3')
var uuid = require('uuid')
// Unique bucket name
const bucketName = 'node-sdk-sample-' + uuid.v4()
// Name for uploaded object
const keyName = 'hello_world.txt'
const client = new S3Client({})
const createCommand = new CreateBucketCommand({
Bucket: bucketName
})
const putCommand = new PutObjectCommand({
Bucket: bucketName,
Key: keyName,
Body: 'Hello World!'
})
try {
await client.send(createCommand)
await client.send(putCommand)
console.log('Successfully uploaded data to ' + bucketName + '/' + keyName)
} catch (err) {
console.error(err, err.stack)
}