【问题标题】:S3 getPresignedUrl Invalid access key NodejsS3 getPresignedUrl 无效的访问密钥 Nodejs
【发布时间】:2023-02-24 03:47:04
【问题描述】:

我从以下函数获取 S3 存储桶(.opus 文件)的 presignedUrl:

function Get Recording URL(bucket, file Path, access Token) {

AWS.config.update({ 
    accessKeyId: accessToken,
    secretAccessKey: accessToken,
    signatureVersion: 'v4',
    region: 'eu-west-2'
});

const s3 = new AWS.S3();
const params = {
    Bucket: bucket,
    Key: filePath,
    Expires: 60000
}

console.log("Bucket:",bucket);
console.log("Filepath:",filePath);
console.log("AccessToken:",accessToken);   

const url = s3.getSignedUrl('getObject', params)

console.log("URL:", url);
return url;

}

它可以很好地生成 URL,但是当我浏览它时,我收到消息:

我将 accessKeyId 和 secretAccessKey 设置为相同的值 (accessToken),我认为这可能是问题所在?我正在使用 Cognito 并像这样登录:

try {
      console.log("Auth", Auth);
      const user = await Auth.signIn(this.state.username, this.state.password);
      console.log(user);
      this.props.auth.setAuthStatus(true);
      this.props.auth.setUser(user);
      this.props.history.push("/SearchScreen");
    }catch(error) {
      let err = null;
      !error.message ? err = { "message": error } : err = error;
      this.setState({
        errors: {
          ...this.state.errors,
          cognito: err
        }
      });
    }
  };

然后使用 user.signInUserSession.getAccessToken().getJwtToken() 获取令牌。我应该使用另一个令牌吗?

【问题讨论】:

    标签: node.js reactjs amazon-s3


    【解决方案1】:

    根据S3 documentation,您只能使用 IAM 用户而不是 Cognito 用户创建预签名 URL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-14
      • 2015-11-18
      • 2021-09-02
      • 2019-04-22
      相关资源
      最近更新 更多