运行放大模拟时无法访问的DynamoDB主机 [英] Inaccessible DynamoDB host when running amplify mock

查看:85
本文介绍了运行放大模拟时无法访问的DynamoDB主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS Amplify设置AppSync GraphQL API.我有一个带有@model批注的架构,我正在尝试编写一个lambda解析器,该读/写器将对@model生成的DynamoDB表进行读取/写入.但是,当我尝试使用amplify mock在本地进行测试时,我的JS函数抛出了

I am using AWS Amplify to set up an AppSync GraphQL API. I have a schema with an @model annotation and I am trying to write a lambda resolver that will read/write to the DynamoDB table that @model generates. However, when I attempt to test locally using amplify mock my JS function throws

error { UnknownEndpoint: Inaccessible host: `dynamodb.us-east-1-fake.amazonaws.com'. This service may not be available in the `us-east-1-fake' region.

我似乎根本找不到关于此用例的太多文档(大多数lambda解析器示例从其他表/API读取,而这些表/API都不是amplify应用程序的一部分),因此希望使用任何指针.是否甚至支持运行这种类型的设置,还是我必须推送到AWS才能进行测试?

I can't seem to find much documentation around this use case at all (most examples of lambda resolvers read from other tables / APIs that are not part of the amplify app) so any pointers are appreciated. Is running this type of setup even supported or do I have to push to AWS in order to test?

推荐答案

深入研究Amplify CLI代码后,我发现了一个目前可以使用的解决方案.

After some digging into the Amplify CLI code, I have found a solution that will work for now.

在这里amplify mock初始化DynamoDB Local的地方.如您所见,它没有设置--sharedDb标志,该标志基于docs 表示已创建的数据库文件将以请求的访问密钥ID为前缀,然后是区域.根据定义

Here is where amplify mock initializes DynamoDB Local. As you can see, it does not set the --sharedDb flag which based on the docs means that the created database files will be prefixed with the access key id of the request and then the region. The access key id of requests from Amplify will be "fake" and the region is "us-fake-1" as defined here. Furthermore, the port of the DynamoDB Local instance started by Amplify is 62224 defined here.

因此,要连接到Amplify创建的表,需要以下DynamoDB配置

Therefore, to connect to the tables that are created by Amplify, the following DynamoDB config is needed

const ddb = new AWS.DynamoDB({
  region: 'us-fake-1',
  endpoint: "http://172.16.123.1:62224/",
  accessKeyId: "fake",
  secretAccessKey: "fake"
})

如果要对由Amplify创建的表使用AWS CLI,则必须使用上面的区域和访问键创建一个新的配置文件.

If you want to use the AWS CLI with the tables created by Amplify, you'll have to create a new profile with the region and access keys above.

我仍然需要做一些额外的工作,以找出使这些配置值在本地模拟值和实际模拟值之间切换的好方法,但这暂时阻止了本地测试.

I'll still need to do some additional work to figure out a good way to have those config values switch between the local mock values and the actual ones, but this unblocks local testing for now.

关于我对在哪里设置"us-east-1-fake"的AWS :: Region的另一个问题,设置为

As for another question that I had about where AWS::Region of "us-east-1-fake" was being set, that gets set here but it does not appear to be used anywhere else. ie, it gets set as a placeholder value when running amplify mock but using it as a region in other places for testing locally doesn't seem to work.

这篇关于运行放大模拟时无法访问的DynamoDB主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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