aws-samples / amazon-sumerian-hosts

Amazon Sumerian Hosts (Hosts) is an experimental open source project that aims to make it easy to create interactive animated 3D characters for Babylon.js, three.js, and other web 3D frameworks. It leverages AWS services including Amazon Polly (text-to-speech) and Amazon Lex (chatbot).
MIT No Attribution
183 stars 82 forks source link

How to refresh credentials for Polly? #31

Open jkeys-ecg-nmsu opened 3 years ago

jkeys-ecg-nmsu commented 3 years ago

We're using aws-amplify for authentication. There's a helpful API called Auth.currentCredentials() which will return valid credentials generated by the attached identity pool.

I have this effect sitting in my root component:

  /**
   * refresh the AWS credentials
   */
  useEffect( () => {
    const THIRTY_MINUTES_MS = 1800000;
    setInterval( async () => {
      const [creds] = await Promise.all([Auth.currentCredentials()]);
      const { accessKeyId, secretAccessKey, sessionToken } = creds;
      AWS.config.credentials = new AWS.Credentials({
        accessKeyId,
        secretAccessKey,
        sessionToken
      })
    }, THIRTY_MINUTES_MS);
  }, []);

Even with this code, it appears that credentials are expiring after an hour. How can I refresh the AWS credentials for this library?

Thanks.

c-morten commented 3 years ago

Hi @jkeys-ecg-nmsu. We don't do anything in the host API that touches credentials, we just assume that the user has set them up. I'm thinking maybe you need to apply these new credentials to the Polly and PollyPresigner objects you passed to the TextToSpeechFeature.initializeService method, or construct new Polly and PollyPresigner objects using the new credentials and re-initialize the TextToSpeechFeature using those.

c-morten commented 3 years ago

Hi @jkeys-ecg-nmsu, checking in to see if either of the methods I described above fixed your issue or if this needs further investigation.

jkeys-ecg-nmsu commented 3 years ago

Hi @c-morten, sorry for the late reply. Your idea makes a lot of sense to me, so I rewrote my refresh logic to recall initializeService with fresh Polly and Presigner instances. I will try to test it today and let you know if it works and close the issue. Thank you!