AWSOpenSearchpython客户端在client.indices.exists()上引发403错误-需要哪些权限?
创始人
2024-09-26 17:01:06
0

问题是因为使用的AWS OpenSearch版本需要IAM权限才能进行索引操作。以下是解决方案:

  1. 找出具有OpenSearch服务权限的AWS Identity and Access Management (IAM) 用户的 ARN。

  2. 将以下内容添加到IAM用户的策略中。用户的ARN在这个示例中表示了需要更改的部分。

例如:

  "Effect": "Allow",
  "Action": [
    "es:*"
  ],
  "Resource": "arn:aws:es:us-west-2::domain/my-search-domain/*"

在Resource字段中:

  • 将“us-west-2”更改为使用OpenSearch服务的区域。

  • 将“”更改为AWS账户ID。

  • 将“my-search-domain”更改为OpenSearch服务的域名。

  1. 使用AWS SDK for Python(boto3)创建OpenSearch客户端并对其进行身份验证。

例如:

import boto3
from requests_aws4auth import AWS4Auth

host = 'search-my-search-domain-abc123.us-west-2.es.amazonaws.com'
region = 'us-west-2'
service = 'es'

credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)

client = boto3.client('es', region_name=region, aws_access_key_id=credentials.access_key, aws_secret_access_key=credentials.secret_key, aws_session_token=credentials.token)
  1. 然后,在OpenSearch客户端上调用client.indices.exists()。

例如:

index_name = 'my-index-name'

if not client.indices.exists(index_name):
    print('Index does not exist')
else:
    print('Index exists')

通过使用IAM权限,并在OpenSearch客户端上进行身份验证,您可以通过python程序运行OpenSearch操作,以便在OpenSearch索引内进行多种操作。

相关内容

热门资讯

第9分钟辅助!wepokerp... 第9分钟辅助!wepokerplus辅助,pokemmo脚本辅助下载,妙招教程(真实有挂)该软件可以...
7分钟辅助!wepoker究竟... 7分钟辅助!wepoker究竟有没有透视,菠萝德普辅助器免费版在哪里,窍要教程(真实有挂)1、菠萝德...
六分钟辅助!hhpoker辅助... 六分钟辅助!hhpoker辅助软件下载,wpk辅助,妙招教程(有挂秘籍)运hhpoker辅助软件下载...
五分钟辅助!来玩app破解,a... 五分钟辅助!来玩app破解,aapoker ai插件,举措教程(有挂讲解)1、aapoker ai插...
8分钟辅助!菠萝辅助器免费版的... 8分钟辅助!菠萝辅助器免费版的特点,sohoo开挂辅助,讲义教程(有挂秘笈)菠萝辅助器免费版的特点透...
第三分钟辅助!wepoker有... 第三分钟辅助!wepoker有没有挂,wepoker私人局透视,手筋教程(有挂方略)1、操作简单,无...
第九分钟辅助!aapoker透... 第九分钟辅助!aapoker透视插件,菠萝辅助器免费版的特点,绝活教程(有挂技术)1、完成菠萝辅助器...
6分钟辅助!德州透视是真的假的... 6分钟辅助!德州透视是真的假的,wepoker辅助器是真的吗,举措教程(有挂分享)1、wepoker...
四分钟辅助!wepokerpl... 四分钟辅助!wepokerplus外挂,hhpkoer辅助挂是真的吗,法门教程(存在有挂)1、许多玩...
第九分钟辅助!有哪些免费的wp... 第九分钟辅助!有哪些免费的wpk作弊码,wpk辅助哪里买,课程教程(有挂实锤)1)有哪些免费的wpk...