I struggled for hours to use the saved_objects import/export api.
we have an AWS managed OS cluster with cognito and OIDC federate.
spent a lot of hours trying to get programmatically the needed tokens to make the api call work without any result.
then some engineer from the OS team told me to try an OS AWS admin credentials and that did all the thing for me. So a simple code like this just works immediately:
import boto3
import requests
from requests_aws4auth import AWS4Auth
host = host = “https:///”
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)
path = ‘_dashboards/api/saved_objects/_export’
url = host + path
payload = {
“objects”: [
{
“type”: “dashboard”,
“id”: “4faff580-899b-11eb-aa2d-3b285fc0682d”
}
]
}
headers = {“Content-Type”: “application/json”, “osd-xsrf”: “true”, “security_tenant”: “global” }
r = requests.post (url, auth=awsauth, json=payload, headers=headers)
print(r.status_code)
print(r.text)