使用角色而不是密钥在 s3 中签名 url 但没有返回任何错误
using role instead of keys to get signed url in s3 but nothing returned and no errors
我试过如果我使用访问密钥,它工作正常但我正在尝试获取访问密钥并使用角色来代替,但是一旦我获取访问密钥。我在 return 中得到的是 www.aws.amazon.com
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
const params = {Bucket: config.bucket, Expires: config.time, Key};
const url = s3.getSignedUrl('getObject', params);
console.log('The URL is', url);
我什至通过进入我的 ec2 和 运行 cli 命令 aws s3 presign s3://bucket/path/file
来确保我的角色设置正确 我在 [=20= 中获得了签名 url ] 不过这意味着我的角色是正确的,不是吗?
在此先感谢您的任何建议/帮助。
您不能在使用 IAM 角色时同步使用 getSignedUrl()
。
Note: You must ensure that you have static or previously resolved credentials if you call this method synchronously (with no callback), otherwise it may not properly sign the request. If you cannot guarantee this (you are using an asynchronous credential provider, i.e., EC2 IAM roles), you should always call this method with an asynchronous callback.
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
s3.getSignedUrl('getObject', params, function (err, url) {
console.log('The URL is', url);
});
我试过如果我使用访问密钥,它工作正常但我正在尝试获取访问密钥并使用角色来代替,但是一旦我获取访问密钥。我在 return 中得到的是 www.aws.amazon.com
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
const params = {Bucket: config.bucket, Expires: config.time, Key};
const url = s3.getSignedUrl('getObject', params);
console.log('The URL is', url);
我什至通过进入我的 ec2 和 运行 cli 命令 aws s3 presign s3://bucket/path/file
来确保我的角色设置正确 我在 [=20= 中获得了签名 url ] 不过这意味着我的角色是正确的,不是吗?
在此先感谢您的任何建议/帮助。
您不能在使用 IAM 角色时同步使用 getSignedUrl()
。
Note: You must ensure that you have static or previously resolved credentials if you call this method synchronously (with no callback), otherwise it may not properly sign the request. If you cannot guarantee this (you are using an asynchronous credential provider, i.e., EC2 IAM roles), you should always call this method with an asynchronous callback.
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property
s3.getSignedUrl('getObject', params, function (err, url) {
console.log('The URL is', url);
});