'How to upload files into localstack s3 bucket

I have installed localstack into my Linux machine, and also configured AWS CLI, and created a bucket using awslocal as docs suggested. here is the link to create an s3 bucket in localstack. https://docs.localstack.cloud/aws/s3/

And, now I'm trying to upload a file into the bucket, it was throwing an error

InvalidBucketName: The specified bucket is not valid

here is the **bucket name**
{
    "Buckets": [
        {
            "Name": "suresh",
            "CreationDate": "2022-04-20T07:07:59+00:00"
        }
    ],
    "Owner": {
        "DisplayName": "webfile",
        "ID": "bcaf1ffd86f41161ca5fb16fd081034f"
    }
}

here is my code using node js

import fs from 'fs';
import S3 from 'aws-sdk/clients/s3';

const localstack = new S3({
 region: 'eu-west-1', // The value here doesn't matter.
 endpoint: 'http://localhost:4566', // This is the localstack EDGE_PORT
});

export const localstackFileUpload = async () => {
  const fileName = './suresh.txt';
  return localstack
    .upload({
      Bucket: 'suresh',
      Key: fileName,
      Body: fs.readFileSync(fileName),
    })
    .promise()
    .then((res) => {
      console.log(' res ', res);
    })
    .catch((err) => {
      console.log(' err ', err);
    });
};


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source