Advertisement
Guest User

Untitled

a guest
Nov 24th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import boto3
  2. import requests
  3. from requests_aws4auth import AWS4Auth
  4.  
  5. host = '' # include https:// and trailing /
  6. region = '' # e.g. us-west-1
  7. service = 'es'
  8. credentials = boto3.Session().get_credentials()
  9. awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)
  10.  
  11. # Register repository
  12.  
  13. path = '_snapshot/my-snapshot-repo-name' # the Elasticsearch API endpoint
  14. url = host + path
  15.  
  16. payload = {
  17.   "type": "s3",
  18.   "settings": {
  19.     "bucket": "s3-bucket-name",
  20.     "region": "us-west-1",
  21.     "role_arn": "arn:aws:iam::123456789012:role/TheSnapshotRole"
  22.   }
  23. }
  24.  
  25. headers = {"Content-Type": "application/json"}
  26.  
  27. r = requests.put(url, auth=awsauth, json=payload, headers=headers)
  28.  
  29. print(r.status_code)
  30. print(r.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement