Home > database >  AWS GetSignedUrl generates wrong url with us-east-1 region by default
AWS GetSignedUrl generates wrong url with us-east-1 region by default

Time:10-18

I am trying to generate url so that I can download files from AWS. The problem is that the url that generates me has the wrong region set, it should be eu-west-3 and it puts us-east-1 by default. I have looked at the configuration that I have in aws and I have eu-west-3 in the region so I do not know what is happening.

Here is an example of de URL with the wrong region that I get:

https://atlasfitness-trainings-s3.s3.amazonaws.com/7d447302-3542-4fd9-84c4-937255e6ee79-try.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAZGHWWSFLWOHZXUIH/20211018/us-east-1/s3/aws4_request&X-Amz-Date=20211018T053136Z&X-Amz-Expires=300&X-Amz-Signature=17731e93fdf43924b30dfe5691115a51c850786c75ff1692e614bc84c31a3ca3&X-Amz-SignedHeaders=host

When I use aws configure list I get the following:

      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ******************* shared-credentials-file
secret_key     ******************* shared-credentials-file
    region                eu-west-3      config-file    ~/.aws/config

Here we can see region is correct, so I don't know why its happening.

Here is the code I use with nodeJS to generate de URL.

import AWS from 'aws-sdk';

const s3 = new AWS.S3({
    region: process.env.AWS_TRAININGS_BUCKET_REGION, //configured correctly (eu-west-3)
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
    signatureVersion: 'v4'
});

export const getUrlS3 = (fileKey) => {
    const getUrlParams = {
        Key: fileKey,
        Bucket: process.env.AWS_TRAININGS_BUCKET_NAME,
        Expires: 60*5,

    }
    return s3.getSignedUrl('getObject',getUrlParams);;
}

So if anyone know how to fix that issue, I'll be very gratefull to listen it.

CodePudding user response:

I guess you are using Linux or MacOS. So please add some parameters :

export AWS_TRAININGS_BUCKET_REGION=eu-west-3

OR add: [default] into ~/.aws/config

[default]
access_key
secret_key
region
output

OR: put directly :

region: eu-west-3,
  • Related