简体   繁体   中英

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

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%2F20211018%2Fus-east-1%2Fs3%2Faws4_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.

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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM