eheikes / tts

Tools to convert text to speech :books::speech_balloon:
Apache License 2.0
92 stars 19 forks source link

AWS Credentials do not load from credentials file #145

Open MullPointer opened 7 months ago

MullPointer commented 7 months ago

I am able to run tts-cli successfully if I explicitly specify an AWS access-key and secret-key on the command line. But if I put those same values in the [default] section of a ~/.aws/credentials file then I get a "Resolved credential object is not valid" error. The credentials file appears to be valid as it works with "aws sts get-caller-identity" and with my own node.js project using AWS Polly.

  tts-cli called with arguments {"_":["test3.mp3"]} +0ms
  tts-cli input: null +0ms
  tts-cli output: test3.mp3 +1ms
  readText Reading from stdin +0ms
  readText Finished reading (12 bytes) +2ms
  chunkText Chunked into 1 text parts +0ms
  splitText Stripping whitespace +0ms
  generateSpeech Options: {"ffmpeg":"ffmpeg","format":"mp3","limit":5,"region":"us-east-1","type":"text","voice":"Joanna"} +0ms
  create Creating AWS Polly instance in us-east-1 +0ms
  generateAll Requesting 1 audio segments, 5 at a time +0ms
  generate Making request to Amazon Web Services +0ms
  generate Error during request: Resolved credential object is not valid +0ms
  generateAll Requested all parts, with error Error: Resolved credential object is not valid +0ms
Error: Resolved credential object is not valid
    at _SignatureV4.validateResolvedCredentials (/usr/lib/node_modules/tts-cli/node_modules/@smithy/signature-v4/dist-cjs/index.js:440:13)
    at _SignatureV4.signRequest (/usr/lib/node_modules/tts-cli/node_modules/@smithy/signature-v4/dist-cjs/index.js:365:10)

~/.aws/credentials

[default]
aws_access_key_id = xxxxxxx
aws_secret_access_key = xxxxxxxx
region = eu-west-2

no AWS environment variables are set.

MullPointer commented 7 months ago

In my own node project I found I could send an AWS Polly request successfully using the credentials file if I left out the credentials value on the Polly constructor, but not if I specified null values for the access and secret keys as tts-cli seems to do.

That is with this constructor:

const client = new Polly({
  region: "eu-west-2",
  credentials: {
    accessKeyId: null,
    secretAccessKey: null
  }
});

getSynthesizeSpeechUrl would give me the same error: "Resolved credential object is not valid".

But if I take out the credentials parameter entirely it works. Maybe in tts-cli credentials could only be sent if set?