来自AWS Amplify的AWS开发工具包中的S3凭证如何更新

问题描述

我有一个使用Amplify for Auth的应用程序,但是它需要从现有存储桶中读取某些任务。

我可以通过运行类似的东西来获得所需的凭据

#module s3helper.js
let S3 
let currentCreds
let essentialCreds 

//In a getCreds function 
const getCreds = () => new Promise((resolve) => {
  currentCreds = await Auth.currentCredentials()
  essentialCreds = Auth.essentialCredentials(currentCreds)
  S3 = new AWS.S3({credentials: essentialCreds})
  resolve()
}

我已经将所有这些都放入了S3 Helper模块中,因此您可以使用类似s3helper.getFromS3(pathToS3File)之类的东西。

为简单起见,getFromS3函数如下所示:

const getFromS3 = () => {
  await getCreds()
  return S3.getobject(...)

getFromS3方法实际上可以检查凭据是否已过期,如果是,则调用getCreds,但这是最好的方法,每次只使用S3重新创建S3 = new AWS.S3({credentials: essentialCreds})他们被替换吗?有更好的方法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)