def getAWSToken():
region = 'ap-south-1'
service = 'es'
sts_connection = boto3.client('sts',endpoint_url='https://sts.ap-south-1.amazonaws.com', region_name=region)
acct_b = sts_connection.assume_role(
RoleArn="arn:aws:iam::<account-number>:role/Role-Read-Tenant1-Data"
)
ACCESS_KEY = acct_b['Credentials']['AccessKeyId']
SECRET_KEY = acct_b['Credentials']['SecretAccessKey']
SESSION_TOKEN = acct_b['Credentials']['SessionToken']
awsauth = AWS4Auth(ACCESS_KEY, SECRET_KEY, region, service, session_token=SESSION_TOKEN)
return awsauth
def searchDataUsingSQL(indexName, tenantName):
url = "https://"+host+"/_plugins/_sql?format=json"
condition=''
payload = json.dumps({
"query": "select * from " + type.lower() + condition + ";"
})
headers = {
'Content-Type': 'application/json',
'securitytenant': tenantName
}
response = requests.request("POST", url, headers=headers, data=payload, auth=getAWSToken())
我们可以利用 searchUsingSQL() 中的“securitytenant”标头使用 API 选择特定租户的索引吗?