amazon-sumerian-hosts icon indicating copy to clipboard operation
amazon-sumerian-hosts copied to clipboard

How to refresh credentials for Polly?

Open jkeys-ecg-nmsu opened this issue 5 years ago • 3 comments

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.

jkeys-ecg-nmsu avatar Nov 09 '20 19:11 jkeys-ecg-nmsu

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 avatar Nov 12 '20 14:11 c-morten

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.

c-morten avatar Nov 22 '20 17:11 c-morten

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!

jkeys-ecg-nmsu avatar Nov 30 '20 18:11 jkeys-ecg-nmsu