我已经使用ask-sdk使用了我自己的自定义webhook,并部署在我的ec2实例中。现在我想使用DynamoDB作为DynamoDbPersistenceAdapter,但是我没有得到任何关于如何做到这一点的参考。
DynamoDbPersistenceAdapter将需要AWS密钥和表名称,以及发电机数据库的一些详细信息,但在哪里初始化?我找到了一些代码,但这里没有任何东西:
persistenceAdapter = new DynamoDbPersistenceAdapter({
tableName: 'global_attr_table',
createTable: true,
partitionKeyGenerator: keyGenerator
});发布于 2019-06-18 00:43:51
这可能可以通过添加环境变量和设置AWS CLI配置文件来解决:
下面是如何设置AWS CLI配置文件:https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
使用AWS访问信息设置配置文件后,即可在命令行或shell脚本中导出环境变量
$> export AWS_PROFILE=YourNewAWSCLIProfileName
$> export AWS_REGION=us-east-1
$> export AWS_DEFAULT_REGION=us-east-1您可以通过输入以下命令来检查这些变量是否已设置
$> echo $AWS_PROFILE
$> echo $AWS_REGION
$> echo $AWS_DEFAULT_REGION这就是我所使用的。如果由于某些原因不起作用,这里有一些关于如何添加DynamoDB客户端的研究:
尝试解决一个不同的问题,因此让我在遍历我的问题时解决您的问题: In: node_modules/ask-sdk/dist/skill/factory/StandardSkillFactory.js中有类似于上面的内容的引用
new ask_sdk_dynamodb_persistence_adapter_1.DynamoDbPersistenceAdapter({
tableName: thisTableName,
createTable: thisAutoCreateTable,
partitionKeyGenerator: thisPartitionKeyGenerator,
dynamoDBClient: thisDynamoDbClient,
})我认为您需要创建一个DynamoDbClient实例,我在AWS SDK文档中找到了该实例。
你必须设置你自己的服务: In: node_modules/aws-sdk/lib/dynamodb/document_client.js
/**
* Creates a DynamoDB document client with a set of configuration options.
*
* @option options params [map] An optional map of parameters to bind to every
* request sent by this service object.
* @option options service [AWS.DynamoDB] An optional pre-configured instance
* of the AWS.DynamoDB service object to use for requests. The object may
* bound parameters used by the document client.
* @option options convertEmptyValues [Boolean] set to true if you would like
* the document client to convert empty values (0-length strings, binary
* buffers, and sets) to be converted to NULL types when persisting to
* DynamoDB.
* @see AWS.DynamoDB.constructor
*
*/
constructor: function DocumentClient(options) {
var self = this;
self.options = options || {};
self.configure(self.options);
},
/**
* @api private
*/
configure: function configure(options) {
var self = this;
self.service = options.service;
self.bindServiceObject(options);
self.attrValue = options.attrValue =
self.service.api.operations.putItem.input.members.Item.value.shape;
},
/**
* @api private
*/
bindServiceObject: function bindServiceObject(options) {
var self = this;
options = options || {};
if (!self.service) {
self.service = new AWS.DynamoDB(options);
} else {
var config = AWS.util.copy(self.service.config);
self.service = new self.service.constructor.__super__(config);
self.service.config.params =
AWS.util.merge(self.service.config.params || {}, options.params);
}
},我不确定这些选项会是什么样子。
https://stackoverflow.com/questions/56516157
复制相似问题