amazon-web-services - Appsync + Elasticsearch:执行对 OpenSearch 的请求时出现通信错误
问题描述
我正在尝试在 Appsync (graphql) 和 ElasticSearch(V7.10) 之间进行快速 poc,但是当 Appsync(resolver) 尝试调用 ES 时出现以下通信错误。它是一个简单的 graphql 查询。
我尝试按照这个 poc 的教程:https ://docs.aws.amazon.com/appsync/latest/devguide/tutorial-elasticsearch-resolvers.html
对 appsync 和 elasticsearch 都启用了 Cloudwatch Logs,但这个错误并没有太多。非常感谢您对此的任何帮助。
下面是详细信息。
ES:版本 7.10(也尝试使用 OpenSearch 1.0,但同样的错误),它在 vpc 中,appsync 是在与 vpc 相同的区域中创建的。
错误 :
{
"data": {
"allPosts": null
},
"errors": [
{
"path": [
"allPosts"
],
"data": null,
"errorType": "OpenSearch:RuntimeException",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "Communication error while executing a request to OpenSearch."
}
]
}
请求映射模板(解析器)
{
"version":"2017-02-28",
"operation":"GET",
"path":"/item_catlog_001/_doc/_search",
"params":{
"body": {
"from": 0,
"size": 50,
"query": {
"match_all": {}
}
}
}
}
IAM 在 Appsync 端的角色
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"es:ESHttpDelete",
"es:ESHttpHead",
"es:ESHttpGet",
"es:ESHttpPost",
"es:ESHttpPut"
],
"Resource": [
"arn:aws:es:ap-southeast-2:*:domain/helloworld/*"
]
}
]
}
信任关系
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "appsync.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
ES/OS 端的访问策略
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "es:*",
"Resource": "arn:aws:es:ap-southeast-2:*:domain/helloworld/*"
},
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::*:role/service-role/appsync-ds-es-57leg5-vpc-helloworld-o53f5"
},
"Action": [
"es:ESHttpDelete",
"es:ESHttpHead",
"es:ESHttpGet",
"es:ESHttpPost",
"es:ESHttpPut"
],
"Resource": "arn:aws:es:ap-southeast-2:*:domain/helloworld/*"
}
]
}
谢谢瓦苏
_
解决方案
如果您在 VPC 后面有 ElasticSearch,您将看到此错误。看一下这个
AWS AppSync 支持从您在自己的 AWS 账户中预置的域中使用 Amazon OpenSearch Service,前提是它们不存在于 VPC 中
https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-elasticsearch-resolvers.html
这也是一个困扰我的问题——我管理的最佳解决方案是在与弹性搜索相同的 VPC 后面创建一个 lambda 代理;让 lambda 接受您的 ES 搜索字符串并将其传递并将结果返回给您的 AppSync 解析器 - AppSync 可以在 VPC 后面使用 lambda(但由于某种原因不是 OpenSearch)
推荐阅读
- scala - 使用 Scala Spark 在不同组中计算复杂统计数据的困难
- java - 使用 spring boot / thymyleaf 重定向到 HTML 页面
- go - 是自定义命名类型的转换函数还是语言构造
- android - 启动阻塞 GC Alloc / 等待阻塞 GC Alloc
- reactjs - React 功能组件,如何通过 onChange 事件动态地将属性传递给输入元素
- android - 将 Recycler View 边缘效果剪辑到 Recycler View Background Drawable
- javascript - 如何从 Prisma 1 迁移到 Prisma 2
- r - R - 带有 if 语句的三重循环跳过错误的行
- php - Azure php web_app 系统临时目录不可用
- ssas - MS SSAS 监控?