由于函数调用中缺少区域而导致AWS Config错误

时间:2018-11-08 18:05:12

标签: amazon-web-services aws-sdk aws-regions

 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);

我正在通过aws.config.update设置该区域。但是,当我尝试进行DynamoDB / S3 / Firehose / KMS调用时,会导致ConfigError。

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

解决方法是将区域放入呼叫中,以便-new aws.KMS({region}).listAliases

aws.config.update不能解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

如果我想在全球范围内使用awsConfigurationParameters,则需要更新aws.config。在我的示例中,只有awsConfig正在更新。

尝试以下方法:

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);

更新全局配置后,所有客户端都将使用该配置:

const kmsClient = new aws.KMS();