Lambda函数更改端点

时间:2018-09-21 22:54:07

标签: javascript node.js aws-lambda

我对Lambda有点陌生,正尝试从Support(us-east-1)中提取一些数据,然后读/写到DynamoDB(我正在使用本地dynamodb-local实例),但是我不知道如何更改区域。

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

AWS.config.update({
  region: 'us-east-1',
});

const support = new AWS.Support({
  region: 'us-east-1',
  apiVersion: '2013-04-15'
});

const supportParams = {
  checkId: 'Qch7DwouX1',
  language: 'en'
};

let stuff = {};

support.describeTrustedAdvisorCheckResult(supportParams, (err, data) => {
  if(err) console.log('Error: ', err.stack);
  else {
     stuff[test] = [...data]
  };
}

// Now I want to pull some data from DynamoDB locally or in another region
//
// AWS.config.update({endpoint: 'http://localhost:8000});
// 

如何将端点更改为http://localhost:8000或us-west-2以便从DynamoDB中获取信息?我不应该在1个lambda函数中更改区域/端点吗?

我正在尝试类似的事情:

const dynaDB = new AWS.DynamoDB({endpoint: 'http://localhost:8000'})
const dynaClient = new AWS.DynamoDB.DocumentClient();

dynaClient.scan({}, (err, data) => {
  ..
  ..
  ..
}

1 个答案:

答案 0 :(得分:0)

当我们要在两个区域之间复制时,我们遇到了同样的问题。

您可以为每个dynamodb实例化一个aws-sdk,

const AWSregion = require('aws-sdk');
AWSregion.config.update({
  region: 'us-east-1',
});
// Connect to us-east-1 with AWSregion

const AWSlocal = require('aws-sdk');  // Don't set any region here, since it is local
// Connect to local dynamodb with AWSlocal

希望有帮助。