如何在AWS js SDK中配置区域? [英] How to configure the region in the AWS js SDK?

查看:247
本文介绍了如何在AWS js SDK中配置区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的js函数,该函数从AWS CloudWatch Logs中读取一些信息。

I am writing a simple js function that reads some information from AWS CloudWatch Logs.

按照在Node.js AWS开发工具包中配置区域的答案,以及 AWS nodejs SDK文档,提出以下内容:

Following the answer at Configuring region in Node.js AWS SDK, and the AWS nodejs SDK documentation, I came up with the following:

var AWS = require('aws-sdk');

var cloudwatchlogs = new AWS.CloudWatchLogs();

console.log(AWS.config.region)              // Undefined

AWS.config.region = 'eu-central-1'          // Define the region with dot notation
console.log(AWS.config.region) .            // eu-central-1

AWS.config.update({region:'eu-central-1'}); // Another way to update
console.log(AWS.config.region) .            // eu-central-1


var params = {
  limit: 0,
//   logGroupNamePrefix: 'STRING_VALUE',
//   nextToken: 'STRING_VALUE'
};

// This call is failing
cloudwatchlogs.describeLogGroups(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});



输出和错误



Output and error

undefined
eu-central-1
eu-central-1
{ ConfigError: Missing region in config
    at Request.VALIDATE_REGION (/Users/adam/binaris/adam-test-sls/node_modules/aws-sdk/lib/event_listeners.js:91:45)
    at Request.callListeners (/Users/adam/binaris/adam-test-sls/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at callNextListener (/Users/adam/binaris/adam-test-sls/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
    at /Users/adam/binaris/adam-test-sls/node_modules/aws-sdk/lib/event_listeners.js:85:9
    at finish (/Users/adam/binaris/adam-test-sls/node_modules/aws-sdk/lib/config.js:315:7)
    at /Users/adam/binaris/adam-test-sls/node_modules/aws-sdk/lib/config.js:333:9
    at SharedIniFileCredentials.get (/Users/adam/binaris/adam-test-sls/node_modules/aws-sdk/lib/credentials.js:126:7)
    at getAsyncCredentials (/Users/adam/binaris/adam-test-sls/node_modules/aws-sdk/lib/config.js:327:24)
    at Config.getCredentials (/Users/adam/binaris/adam-test-sls/node_modules/aws-sdk/lib/config.js:347:9)
    at Request.VALIDATE_CREDENTIALS (/Users/adam/binaris/adam-test-sls/node_modules/aws-sdk/lib/event_listeners.js:80:26)
  message: 'Missing region in config',
  code: 'ConfigError',
  time: 2017-07-11T09:57:55.638Z } ...



环境



代码在本地运行在节点v8.1.2 下。

如何在AWS js SDK中正确配置区域?

打开 github上的一个问题并得到一些

推荐答案

或者,也可以在创建c时指定扬声器对象:

Or, alternatively, you can specify that when creating your cloudwatch object:

var AWS = require('aws-sdk');
var cloudwatchlogs = new AWS.CloudWatchLogs({region: 'eu-central-1'});

这篇关于如何在AWS js SDK中配置区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆