I'm trying to save a string as a file to an AWS S3 bucket using the AWS SDK for NodeJS. The PUT request gets succeeded, but the file does not get created in the S3 bucket. Following is a snippet from my code.
const s3 = new S3({ apiVersion: '2006-03-01' });
const JS_code = `
let x = 'Hello World';
`;
// I'm using the following method inside an async function.
await s3.putObject({
Bucket: 'my-bucket-gayashan',
Key: 'myFile.js',
ContentType:'binary',
Body: Buffer.from(JS_code, 'binary')
});
Can someone please help me with this?
You should use promise() with await
:
await s3.putObject({...}).promise();
You should provide a valid MIME type in the ContentType
field. In your case it should be application/javascript
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With