amazon-web-servicesaws-sdkaws-regions

AWS Config Error due to missing region in function call


 import * as aws from 'aws-sdk';
 ...
 const awsConfigurationParmeters: ConfigurationOptions = {
    logger,
    maxRetries: 10,
    region
  };

  if (Object.keys(customHttpOptions).length > 0) {
    awsConfigurationParmeters.httpOptions = customHttpOptions;
  }

  const awsConfig = new aws.Config();
  awsConfig.update(awsConfigurationParmeters);

I am setting the region golabally via aws.config.update. However, when I trie to make DynamoDB/S3/Firehose/KMS calls, it results in a ConfigError.

"before all" hook: Error calling new aws.KMS.listAliases - Error Code: ConfigError

The Fix is to put region in the call, so that - new aws.KMS({region}).listAliases.

Should't aws.config.update take care of this?


Solution

  • If I want awsConfigurationParameters to be used globally, I need to update aws.config. In my example, only a awsConfig is getting updated.

    Trying this instead:

    import * as aws from 'aws-sdk';
     ...
     const awsConfigurationParmeters: ConfigurationOptions = {
        logger,
        maxRetries: 10,
        region
      };
    
      if (Object.keys(customHttpOptions).length > 0) {
        awsConfigurationParmeters.httpOptions = customHttpOptions;
      }
    
      aws.config.update(awsConfigurationParmeters);
    

    Once the global config is updated, any clients will use that config:

    const kmsClient = new aws.KMS();