我正在尝试使用 opensearch python 客户端(开发目的,非生产)从 AWS Lambda 连接到 AWS OpenSearch 域。
我正在尝试以下操作:
from opensearchpy import OpenSearch
import boto3
from requests_aws4auth import AWS4Auth
import os
import config
my_region = os.environ['AWS_REGION']
service = 'es' # still es???
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, my_region, service, session_token=credentials.token)
openSearch_endpoint = config.openSearch_endpoint
# sth wrong here:
openSearch_client = OpenSearch(hosts = [openSearch_endpoint], auth = awsauth)
Run Code Online (Sandbox Code Playgroud)
根据以下博客:
但它不起作用(它不想进行身份验证,"errorMessage":"AuthorizationException(403, '')"。但是,如果我不使用 python 客户端,而只是简单地执行requests以下操作:
import requests
host = config.openSearch_endpoint
url = host + '/' …Run Code Online (Sandbox Code Playgroud)