【问题标题】:On AWS elastic search {"Message":"User: anonymous is not authorized to perform: es:ESHttpGet"}在 AWS 弹性搜索 {"Message":"User:anonymous is not authorized to perform:es:ESHttpGet"}
【发布时间】:2020-10-25 13:38:24
【问题描述】:

我已经创建了 AWS elasticsearch 域

https://search-xx-xx.us-east-1.es.amazonaws.com/

点击下面的弹性网址和kibana是我得到的错误

{"Message":"用户:匿名无权执行:es:ESHttpGet"}

下面是运行良好的代码

import boto3
from requests_aws4auth import AWS4Auth
from elasticsearch import Elasticsearch, RequestsHttpConnection
session = boto3.session.Session()
credentials = session.get_credentials()

awsauth = AWS4Auth(credentials.access_key,
                   credentials.secret_key,
                   session.region_name, 'es',
                   session_token=credentials.token)
es = Elasticsearch(
    ['https://search-testelastic-2276kyz2u4l3basec63onfq73a.us-east-1.es.amazonaws.com'],
    http_auth=awsauth,
    use_ssl=True,
    verify_certs=True,
    connection_class=RequestsHttpConnection
)


def lambda_handler(event, context):
    es.cluster.health()
    es.indices.create(index='my-index', ignore=400)
    r = [{'Name': 'Dr. Christopher DeSimone', 'Specialised and Location': 'Health'},
 {'Name': 'Dr. Tajwar Aamir (Aamir)', 'Specialised and Location': 'Health'},
 {'Name': 'Dr. Bernard M. Aaron', 'Specialised and Location': 'Health'},
 {'Name': 'Eliana M. Aaron', 'Specialised and Location': 'Health'},
 {'Name': 'Dr. Joseph J. Aaron', 'Specialised and Location': 'Health'},
 {'Name': 'Dr. Michael R. Aaron', 'Specialised and Location': 'Health'},
 {'Name': 'Dr. Darryl H. Aarons', 'Specialised and Location': 'Health'},
 {'Name': 'Dr. William B. Aarons', 'Specialised and Location': 'Health'},
 {'Name': 'Dr. Sirike T. Aasmaa', 'Specialised and Location': 'Health'},
 {'Name': 'Dr. Jacobo A. Abadi', 'Specialised and Location': 'Health'}]
    for e in enumerate(r):
         es.index(index="my-index", body=e[1])

以下是访问政策

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:us-east-1:xxxxxx:domain/xxxxx/*",
      "Condition": {
        "IpAddress": {
          "aws:SourceIp": "*"
        }
      }
    }
  ]
}

【问题讨论】:

    标签: python amazon-web-services aws-lambda aws-elasticsearch


    【解决方案1】:

    此错误表明您的 ElasticSearch 服务不支持匿名请求(未使用有效 IAM 凭证签名的请求)。

    虽然您的政策看起来不错,但官方允许所有政策如下所示

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": {
            "AWS": "*"
          },
          "Action": "es:*",
          "Resource": "arn:aws:es:us-east-1:xxxxxx:domain/xxxxx/*"
        }
      ]
    }
    

    【讨论】:

    • 可能需要设置session变量作为替代
    • 感谢它运行良好,您在哪里得到这个先生,在我看不到的文档中
    • 我的 kibana 加载时间过长
    • 当您有能力从控制台生成时,它有一个名为“允许对域的开放访问”的预定选项
    • 嗯,是否可以在任何隐身窗口帮助中访问它?
    【解决方案2】:

    尝试在 Postman 使用 AWS Signature 身份验证方法进行测试

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2022-01-28
    • 1970-01-01
    • 2016-10-03
    • 2021-05-27
    • 1970-01-01
    • 1970-01-01
    • 2021-10-11
    • 1970-01-01
    • 2023-03-07
    相关资源
    最近更新 更多