“Region is missing” error for Amazon S3 PutObjectCommand even though region is specified

I’m working on project where I need to upload an image file (e.g., .png) to an Amazon S3 bucket. I’ve been through many examples, and as far as I can tell, I’ve been following everything the same. I finally progressed to a point where the error I am getting is “Error: Region is missing”. However, I have specified the region, and I have double-checked it is the same region specified on my bucket in the correct format (e.g., “us-west-1”). I’m just not sure any other direction to proceed in, so any direction would be helpful. Note that the file I am trying to upload is of format:

Main photo file: [
{
fieldname: ‘mainPhoto’,
originalname: ‘mainPhoto.png’,
encoding: ‘7bit’,
mimetype: ‘image/png’,
buffer: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 07 ac 00 00 03 28 08 06 00 00 00 7b c3 1e 08 00 00 0c 3f 69 43 43 50 49 43 43 20 50 72 6f 66 69 … 2666634 more bytes>,
size: 2666684
}
]

Here is the code (React). The image I am trying to upload is mainPhotoFile.

require('dotenv').config();
const express = require('express');
const multer = require('multer');
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
// const { getSignedURL } = require('@aws-sdk/s3-rquest-presigner')
const { Pool } = require('pg');
const cors = require('cors');
const fs = require('fs');

const app = express();
app.use(cors());

const REGION = process.env.AWS_REGION;
const BUCKET = process.env.S3_BUCKET_NAME;
// Configure AWS SDK
const s3Client = new S3Client({
  region: REGION
  credentials: {
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  },
});
const pool = new Pool({
  user: 'postgres',
  host: 'localhost',
  database: 'databaseName',
  password: '********',
  port: 5432,
});
app.get('/api/projects', async(req, res) => {
  const { offset = 0, limit = 10 } = req.query;
  const rows = await pool.query('SELECT * FROM portfolio LIMIT $1 OFFSET $2', [limit, offset]);
  res.json(rows);
})

const upload = multer();

app.post('/upload', upload.fields([{ name: 'mainPhoto', maxCount: 1 }, { name: 'auxPhoto1', maxCount: 1 }]), async (req, res) => {
  try {
    const files = req.files;
    const mainPhotoFile = files.mainPhoto ? files.mainPhoto : null;
    const auxPhotoFile = files.auxPhoto1 ? files.auxPhoto1 : null;

    let mainPhotoURL = null;
    let auxPhotoURL = null;

    console.log('Main photo file:', mainPhotoFile);
    console.log('Aux photo file:', auxPhotoFile);

    if (mainPhotoFile) {
      const mainPhotoParams = {
        Bucket: BUCKET,
        Key: mainPhotoFile.originalname,
        Body: mainPhotoFile,
        ContentType: mainPhotoFile.mimetype,
      };
      const mainPhotoCommand = new PutObjectCommand(mainPhotoParams);
      const mainPhotoData = await s3Client.send(mainPhotoCommand);
      mainPhotoURL = `https://${mainPhotoParams.Bucket}.s3.${REGION}.amazonaws.com/${mainPhotoParams.Key}`;
    }

    // if (auxPhotoFile) {
    //   const auxPhotoParams = {
    //     Bucket: 'your-bucket-name',
    //     Key: auxPhotoFile.originalname,
    //     Body: fs.createReadStream(auxPhotoFile.path),
    //     ContentType: auxPhotoFile.mimetype,
    //   };
    //   const auxPhotoCommand = new PutObjectCommand(auxPhotoParams);
    //   const auxPhotoData = await s3.send(auxPhotoCommand);
    //   auxPhotoURL = `https://${auxPhotoParams.Bucket}.s3.${process.env.AWS_REGION}.amazonaws.com/${auxPhotoParams.Key}`;
    // }

    const { clientName, clientTag1, clientTag2, clientTag3, clientDesc, clientNeeds, companySolution } = req.body;

    const query = `
      INSERT INTO portfolio (
        clientname,
        clienttag1,
        clienttag2,
        clienttag3,
        clientdesc,
        clientneeds,
        companysolution,
        mainphotourl,
        auxphoto1url
      ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
    `;

    const values = [
      clientName,
      clientTag1,
      clientTag2,
      clientTag3,
      clientDesc,
      clientNeeds,
      companySolution,
      mainPhotoURL,
      auxPhotoURL
    ];

    await pool.query(query, values);
    res.send('Data uploaded and inserted successfully.');
  } catch (err) {
    console.error(err);
    res.status(500).send('Error uploading data and files.');
  }
});


const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});