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索引内进行多种操作。

相关内容

热门资讯

操作透视!hhpoker免费透... hhpoker免费透视脚本是一款专注玩家量身打造的游戏记牌类型软件,在hhpoker免费透视脚本这款...
资料透视!werplan免费挂... 您好:werplan免费挂下载这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
绝活透视!德普之星怎么设置埋牌... 绝活透视!德普之星怎么设置埋牌,wepoker透视版下载,安装教程(有挂秘籍)-哔哩哔哩 【无需打开...
方式透视!wpk辅助,wepo... 方式透视!wpk辅助,wepoker怎么挂底牌,靠谱教程(有挂神器)-哔哩哔哩;亲,wepoker怎...
窍门透视!wepoker私人局... 窍门透视!wepoker私人局辅助器怎么用,红龙poker辅助指令,玩家教你(有挂秘笈)-哔哩哔哩 ...
项目透视!wepoker永久免... 大家好,今天小编来为大家解答wepoker永久免费脚本这个问题咨询软件客服可以免费测试直接加微信(1...
机巧透视!aapoker辅助插... 机巧透视!aapoker辅助插件工具,We poker辅助器下载,攻略教程(有挂神器)-哔哩哔哩 >...
模板透视!pokemmo手机版... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
绝活透视!wpk软件是真的吗,... 绝活透视!wpk软件是真的吗,wepoker私人局俱乐部辅助,透牌教程(确实有挂)-哔哩哔哩;亲,w...
经验透视!哈糖大菠萝助手,we... 经验透视!哈糖大菠萝助手,wepoker透视脚本,新2026版(有挂详情)-哔哩哔哩>>您好:软件加...