[英]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.我正在尝试生成 url,以便我可以从 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.
问题是生成我的 url 设置了错误的区域,它应该是 eu-west-3 并且它默认放置 us-east-1。 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.
我查看了我在 aws 中的配置,并且我在该地区有 eu-west-3,所以我不知道发生了什么。
Here is an example of de URL with the wrong region that I get:这是我得到的错误区域的 de URL 示例:
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
https://atlasfitness-trainings-s3.s3.amazonaws.com/7d447302-3542-4fd9-84c4-937255e6ee79-try.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-CredentialUISAKIA%2FAKIA1 2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211018T053136Z&X-Amz-Expires=300&X-Amz-Signature=17731e93fdf43924b30dfe56911850784b3cHeader28c8c8c3c8c8c18c8c16cHeader
When I use aws configure list I get the following:当我使用 aws configure list 时,我得到以下信息:
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.这是我使用 nodeJS 生成 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.我猜你使用的是 Linux 或 MacOS。 So please add some parameters :
所以请添加一些参数:
export AWS_TRAININGS_BUCKET_REGION=eu-west-3
OR add: [ default]
into ~/.aws/config
或添加: [
default]
到~/.aws/config
[default]
access_key
secret_key
region
output
OR: put directly :或:直接放:
region: eu-west-3,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.