AWS Big Data Blog
Unleash the power of Snapshot Management to take automated snapshots using Amazon OpenSearch Service
Data is the lifeblood of any organization, and the importance of protecting it cannot be overstated. Starting with OpenSearch v2.5 in Amazon OpenSearch Service, we introduced Snapshot Management, which automates the process of taking snapshots of your domain. Snapshot Management helps you create point-in-time backups of your domain using OpenSearch Dashboards, including both data and configuration settings (for visualizations and dashboards). You can use these snapshots to restore your cluster to a specific state, recover from potential failures, and even clone environments for testing or development purposes.
Before this release, to automate the process of taking snapshots, you needed to use the snapshot action of OpenSearch’s Index State Management (ISM) feature. With ISM, you could only back up a particular index. Automating backup for multiple indexes required you to write custom scripts or use external management tools. With Snapshot Management, you can automate snapshotting across multiple indexes to safeguard your data and ensure its durability and recoverability.
In this post, we share how to use Snapshot Management to take automated snapshots using OpenSearch Service.
Solution overview
We demonstrate the following high-level steps:
- Register a snapshot repository in OpenSearch Service (a one-time process).
- Configure a sample ISM policy to migrate the indexes from hot storage to the UltraWarm storage tier after the indexes meet a specific condition.
- Create a Snapshot Management policy to take an automated snapshot for all indexes present across different storage tiers within a domain.
As of this writing, Snapshot Management doesn’t support single snapshot creation for all indexes present across different storage tiers within OpenSearch Service. For example, if you try to create a snapshot on multiple indexes with * and some indexes are in the warm tier, the snapshot creation will fail.
To overcome this limitation, you can use index aliases, with one index alias for each type of storage tier. For example, every new index created in the cluster will belong to the hot alias. When the index is moved to the UltraWarm tier via ISM, the alias for the index will be modified to warm, and the index will be removed from the hot alias.
Register a manual snapshot repository
To register a manual snapshot repository, you must create and configure an Amazon Simple Storage Service (Amazon S3) bucket and AWS Identity and Access Management (IAM) roles. For more information, refer to Prerequisites. Complete the following steps:
- Create an S3 bucket to store snapshots for your OpenSearch Service domain.
- Create an IAM role called
SnapshotRole
with the following IAM policy to delegate permissions to OpenSearch Service (provide the name of your S3 bucket):
- Set the trust relationship for
SnapshotRole
as follows:
- Create a new IAM role called
RegisterSnapshotRepo
, which delegatesiam:PassRole
andes:ESHttpPut
(provide your AWS account and domain name):
- If you have enabled fine-grained access control for your domain, map the snapshot role
manage_snapshots
to yourRegisterSnapshotRepo
IAM role in OpenSearch Service. - Now you can use Python code like the following example to register the S3 bucket you created as a snapshot repository for your domain. Provide your host name, Region, snapshot repo name, and S3 bucket. Replace
"arn:aws:iam::123456789012:role/SnapshotRole"
with the ARN of yourSnapshotRole
. The Boto3 session should use theRegisterSnapshotRepo
IAM role.
The S3 bucket used as a repository must be in the same Region as your domain. You can run the preceding code in any compute instance that has connectivity to your OpenSearch Service domain, such as Amazon Elastic Compute Cloud (Amazon EC2), AWS Cloud9, or AWS Lambda. If your domain is within a VPC, then the compute instance should be running inside the same VPC or have connectivity to the VPC.
If you have to register the snapshot repository from a local machine, replace the following lines in the preceding code:
Replace this code with the following and assume the RegisterSnapshotRepo
role (make sure the IAM entity that you are using has appropriate permission to assume the RegisterSnapshotRepo
role). Modify "arn:aws:iam::123456789012:role/RegisterSnapshotRepo"
with the ARN of your RegisterSnapshotRepo
role.
Upon successfully running the sample code, you should receive output such as the following:
You can also verify that you have successfully registered the snapshot repository by accessing OpenSearch Dashboards in your domain and navigating to Snapshots Managements, Repositories.
Create an index template
Index templates enable you to automatically assign configuration when new indexes are created that match a wildcard index pattern.
- Navigate to your domain’s OpenSearch Dashboards and choose the Dev Tools tab.
- Enter the following text in the left pane and choose the play icon to run it.
The index template applies to newly created indexes that match the pattern of "log*"
. These indexes are attached to the alias named hot
and the replica count is set to 1.
Note that in the preceding example, you assign the template to indexes that match "log*"
. You can modify index_patterns
for your use case.
Create an ISM policy
In this step, you create the ISM policy that updates the alias of an index before it is migrated to UltraWarm. The policy also performs hot to warm migration. This is to overcome the limitations where a snapshot can’t be taken across two storage tiers (hot and UltraWarm). Complete the following steps:
- Navigate to the Dev Tools page of OpenSearch Dashboards.
- Create the ISM policy using the following command (modify the values of
index_patterns
andmin_index_age
accordingly):
Create a snapshot policy
In this step, you create a snapshot policy, which takes a snapshot for all the indexes aliased as hot and stores them to your repository at the scheduled time in the cron expression (midnight UTC). Complete the following steps:
- Navigate to the Dev Tools page of OpenSearch Dashboards.
- Create the snapshot policy using the following command (modify the value of
snapshot-repo-name
to the name of the snapshot repository you registered previously):
Clean up
Snapshots that you create incur cost in the S3 bucket used as the repository. With the new Snapshots Management feature, you can easily list and delete unwanted snapshots, and delete the ISM policy to stop taking manual snapshots directly from OpenSearch Dashboards.
Conclusion
With the new Snapshot Management capabilities of OpenSearch Service, you can create regular backups and ensure the availability of your data even in the event of unexpected events or disasters. In this post, we discussed essential concepts such as snapshot repositories, automated snapshot lifecycle policies, and Snapshot Management options, enabling you to make informed decisions when it comes to managing your data backups effectively. As you continue to explore and harness the potential of OpenSearch Service, incorporating Snapshot Management into your data protection strategy will undoubtedly provide you with the resilience and reliability needed to ensure business continuity.
If you have feedback about this post, share it in the comments section. If you have questions about this post, start a new thread on the Amazon OpenSearch Service forum or contact AWS Support.
About the authors
Prashant Agrawal is a Sr. Search Specialist Solutions Architect with Amazon OpenSearch Service. He works closely with customers to help them migrate their workloads to the cloud and helps existing customers fine-tune their clusters to achieve better performance and save on cost. Before joining AWS, he helped various customers use OpenSearch and Elasticsearch for their search and log analytics use cases. When not working, you can find him traveling and exploring new places. In short, he likes doing Eat → Travel → Repeat.
Hendy Wijaya is a Senior OpenSearch Specialist Solutions Architect at Amazon Web Services. Hendy enables customers to leverage AWS services to achieve their business objectives and gain competitive advantages. He is passionate in collaborating with customers in getting the best out of OpenSearch and Amazon OpenSearch
Utkarsh Agarwal is a Cloud Support Engineer in the Support Engineering team at Amazon Web Services. He specializes in Amazon OpenSearch Service. He provides guidance and technical assistance to customers thus enabling them to build scalable, highly available and secure solutions in AWS Cloud. In his free time, he enjoys watching movies, TV series and of course cricket! Lately, he his also attempting to master the art of cooking in his free time – The taste buds are excited, but the kitchen might disagree.