amazon-s3aws-lambda

Error "A region must be set when sending requests to S3." when region is defined


I'm having an issue in my Node.js Lambda where I'm getting presigned URLs for S3, but I'm getting an error that doesn't make any sense.

Here is the method:

async function generateFileReturn(client, fileName, fileKey) {
    console.log('generateFileReturn: process.env.AWS_REGION: ', process.env.AWS_REGION);

    const s3 = new S3Client({
        region: process.env.AWS_REGION,
    });

    const getKeyPromise = getSignedUrl(client, new GetObjectCommand({
        Bucket: `eva-documentation`,
        Key: fileKey,
    }), { expiresIn: 3600 });
    const deleteKeyPromise = getSignedUrl(client, new DeleteCommand({
        Bucket: `eva-documentation`,
        Key: fileKey,
    }), { expiresIn: 3600 });
    
    return {
        label: fileName,
        awsGetUrl: await getKeyPromise,
        awsDeleteUrl: await deleteKeyPromise,
    };
}

But I get this error message:

A region must be set when sending requests to S3.

I've confirmed at the start of the method that the region is correct, so I can't understand where this error is coming from.


Solution

  • The issue was with bad error messaging. I discovered the issue was that I was creating a DeleteCommand instead of a DeleteObjectKeyCommand.