Registering a manual snapshot repository
You need to register a snapshot repository with OpenSearch Service before you can take manual index
snapshots. This one-time operation requires that you sign your AWS request with
credentials that are allowed to access TheSnapshotRole
, as described in
Prerequisites.
Step 1: Map the snapshot role in OpenSearch Dashboards (if using fine-grained access control)
Fine-grained access control introduces an additional step when registering a
repository. Even if you use HTTP basic authentication for all other purposes, you
need to map the manage_snapshots
role to your IAM role that has
iam:PassRole
permissions to pass
TheSnapshotRole
.
-
Navigate to the OpenSearch Dashboards plugin for your OpenSearch Service domain. You can find the Dashboards endpoint on your domain dashboard on the OpenSearch Service console.
-
From the main menu choose Security, Roles, and select the manage_snapshots role.
-
Choose Mapped users, Manage mapping.
-
Add the ARN of the role that has permissions to pass
TheSnapshotRole
. Put role ARNs under Backend roles.arn:aws:iam::
123456789123
:role/role-name
-
Select Map and confirm the user or role shows up under Mapped users.
Step 2: Register a repository
The following Snapshots tab demonstrates how to register a snapshot directory. For options specific to encrypting a manual snapshot and registering a snapshot after migrating to a new domain, see the relevant tabs.
Using the sample Python client
The Python client is easier to automate than a simple HTTP request and has
better reusability. If you choose to use this method to register a snapshot
repository, save the following sample Python code as a Python file, such as
register-repo.py
. The client requires the AWS SDK for Python (Boto3)
Update the following variables in the sample code: host
,
region
, path
, and payload
.
import boto3 import requests from requests_aws4auth import AWS4Auth host = '' # domain endpoint region = '' # e.g. us-west-1 service = 'es' credentials = boto3.Session().get_credentials() awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token) # Register repository path = '/_snapshot/
my-snapshot-repo-name
' # the OpenSearch API endpoint url = host + path payload = { "type": "s3", "settings": { "bucket": "s3-bucket-name
", "base_path": "my/snapshot/directory
", "region": "us-west-1
", "role_arn": "arn:aws:iam::123456789012
:role/snapshot-role
" } } headers = {"Content-Type": "application/json"} r = requests.put(url, auth=awsauth, json=payload, headers=headers) print(r.status_code) print(r.text) # # Take snapshot # # path = '/_snapshot/my-snapshot-repo-name/my-snapshot' # url = host + path # # r = requests.put(url, auth=awsauth) # # print(r.text) # # # Delete index # # path = 'my-index' # url = host + path # # r = requests.delete(url, auth=awsauth) # # print(r.text) # # # Restore snapshot (all indexes except Dashboards and fine-grained access control) # # path = '/_snapshot/my-snapshot-repo-name/my-snapshot/_restore' # url = host + path # # payload = { # "indices": "-.kibana*,-.opendistro_security,-.opendistro-*", # "include_global_state": False # } # # headers = {"Content-Type": "application/json"} # # r = requests.post(url, auth=awsauth, json=payload, headers=headers) # # print(r.text) # # # Restore snapshot (one index) # # path = '/_snapshot/my-snapshot-repo-name/my-snapshot/_restore' # url = host + path # # payload = {"indices": "my-index"} # # headers = {"Content-Type": "application/json"} # # r = requests.post(url, auth=awsauth, json=payload, headers=headers) # # print(r.text)