
Amazon OpenSearch Service is a managed service from Amazon Web Services (AWS) that deploys, operates, and scales OpenSearch clusters, with AWS handling node provisioning, snapshots, software patching, and access control through AWS Identity and Access Management (IAM).
OpenSearch is a distributed search and analytics engine built on Apache Lucene, an open-source full-text search library. It enables you to store, search, analyze, and visualize large volumes of data, making it well suited for use cases such as log analytics, application monitoring, security analytics, and full-text search. It also includes OpenSearch Dashboards, a web-based interface for exploring data, analyzing results, and creating visualizations.
This article explains how to deploy OpenSearch as an alternative to Amazon OpenSearch Service. It covers preparing the host, securing the cluster with your own certificates and users, deploying a three-node cluster with OpenSearch Dashboards using Docker Compose, verifying the deployment, scheduling snapshots to S3-compatible Object Storage, managing index lifecycle policies, monitoring the cluster, and migrating from Amazon OpenSearch Service.
Amazon OpenSearch Service wraps the OpenSearch engine with managed infrastructure and AWS-native access control. The following table maps each Amazon OpenSearch Service component to its self-hosted counterpart and notes where no equivalent exists.
Before you begin, you need to:
OpenSearch memory-maps its index files and locks its Java heap in memory, so disable swap and raise the memory map limit on the host before the containers start.
Disable memory paging and swapping on the host to improve performance.
Comment out any swap entries in the file systems table so that swap stays disabled after a reboot.
Open the sysctl configuration file to raise vm.max_map_count, the maximum number of memory map areas a process can use.
Add the following line, or change the value if the key exists.
Save and close the file.
Reload the kernel parameters.
Verify that the kernel applied the change.
The output returns the value 262144.
The project directory holds the environment file, the security configuration, the certificates, and the Docker Compose file. Docker Compose reads the environment file to fill in the image version, the domain name, and the Dashboards server password.
Create the project directory with subdirectories for certificates and the keystore.
Navigate to the project directory.
Create the environment file.
Add the following configuration:
Replace:
DASHBOARDS_SERVER_PASSWORD with a strong password for the internal kibanaserver user. Keep the single quotation marks so that Docker Compose does not interpret a $ character in the password as a variable.DASHBOARDS_DOMAIN_NAME with your domain name, for example dashboards.example.com.EMAIL_ADDRESS with your email address for Let's Encrypt notifications.Save and close the file.
Restrict access to the environment file to your user, because it contains a password.
The OpenSearch image ships a demo security configuration with known certificates and default users. This deployment disables that demo setup and replaces it with a private certificate authority, node and administrator certificates, and internal users whose passwords only you know. Internal users are accounts stored in the Security plugin's own user database rather than in an external identity provider. Each node presents its node certificate to identify itself and encrypt traffic between nodes and on the REST API. The administrator certificate is a client certificate that authorizes changes to the security configuration.
Create a script that generates the certificate authority and the certificates.
Add the following content:
Save and close the file.
The script follows the OpenSearch self-signed certificate procedure:
root-ca.pem: The certificate authority that every node and client trusts. Keep root-ca-key.pem private, because anyone with it can issue certificates the cluster accepts.admin.pem: The administrator certificate. Its distinguished name (DN) CN=admin,O=EXAMPLE is the only identity allowed to load the security configuration.opensearch-node1.pem to opensearch-node3.pem: One certificate per node. The subject alternative names match the container name and localhost, so clients that verify hostnames accept them.-days 730: Sets a two-year validity period. Renew the certificates before they expire.Run the script.
The certs directory now contains root-ca.pem, admin.pem, admin-key.pem, and a certificate and key for each of the three nodes.
Restrict access to the private keys so that only the file owner can read them.
Give ownership of the certs directory to the user ID 1000 that OpenSearch runs as inside the container.
Create the OpenSearch node configuration file.
Add the following configuration:
Replace OBJECT_STORAGE_HOSTNAME with the hostname shown in your Object Storage subscription details.
Save and close the file.
In the above configuration:
node.pem and node-key.pem: Generic file names that Docker Compose maps to each node's own certificate, so all three nodes share this file.plugins.security.ssl.transport.enforce_hostname_verification: Turns off hostname checks between nodes, because containers reach each other by IP address. Nodes still have to present a certificate signed by your certificate authority with a DN listed in plugins.security.nodes_dn.plugins.security.authcz.admin_dn: The DN of the administrator certificate.plugins.security.restapi.roles_enabled: Lets users mapped to the all_access or security_rest_api_access role manage users, roles, and role mappings through the Security REST API.s3.client.default.region: Required by the repository-s3 plugin. For storage outside AWS, the value has no effect.Generate a password hash for the admin user. The command runs the Security plugin's hashing tool in a temporary container.
Replace ADMIN_PASSWORD with a strong password for the cluster administrator. The last line of the output is the bcrypt hash of the password. Copy it.
Generate a password hash for the kibanaserver user. Use the same password you set as DASHBOARDS_SERVER_PASSWORD in the .env file.
Create the internal users file.
Add the following configuration:
Replace:
ADMIN_PASSWORD_HASH with the hash generated for the admin user.DASHBOARDS_SERVER_PASSWORD_HASH with the hash generated for the kibanaserver user.Save and close the file.
The file defines only these two users, which removes the demo users that ship with the image. A role defines a set of cluster and index permissions, and a role mapping assigns a role to users or backend roles. The default role mappings grant all_access to the admin backend role and the kibana_server role to the kibanaserver user.
Snapshots to S3-compatible Object Storage require the S3 repository plugin, which the stock OpenSearch image does not include. A short Dockerfile adds the plugin, and a separate keystore file holds the Object Storage credentials so that they never become part of an image layer.
Create the Dockerfile.
Add the following content:
Save and close the file.
Build the image.
The build output ends with a line that names the image opensearch-s3:3.10.0. The version in this command, in the hash.sh and keystore commands, and in OPENSEARCH_VERSION in the .env file must match, because Docker Compose runs opensearch-s3:${OPENSEARCH_VERSION} and the Dashboards image uses the same variable.
Give ownership of the keystore directory to the user ID that OpenSearch runs as.
Create the keystore and add the Object Storage credentials. The command prompts for each value without echoing it.
Enter your Object Storage access key and secret key when prompted.
Verify that the keystore file exists.
The output lists the opensearch.keystore file owned by user ID 1000.
This deployment stack uses Docker Compose to run a three-node OpenSearch cluster alongside OpenSearch Dashboards. Traefik acts as a reverse proxy that provides HTTPS access to the Dashboards interface, and persistent volumes retain OpenSearch data across container restarts. The cluster manager node tracks cluster state, such as which nodes have joined, which indices exist, and where shards are allocated. Three cluster-manager-eligible nodes keep a quorum to elect a cluster manager if one node process stops. All three nodes run on one server, so this layout does not survive the loss of the server itself. For production high availability, run each node on a separate server connected through a private network.
Docker publishes container ports with its own firewall rules, which bypass Uncomplicated Firewall (UFW). The Compose file therefore binds the OpenSearch REST API to the loopback interface and publishes only the Traefik ports to the internet.
Create a DNS A record for your Dashboards domain, such as dashboards.example.com, that points to the public IP address of the server. For instructions, see How to Manage DNS Records.
Allow inbound HTTP traffic through the firewall. Traefik uses this port to redirect visitors to HTTPS.
Allow inbound HTTPS traffic through the firewall. Traefik serves OpenSearch Dashboards and completes the Let's Encrypt certificate challenge on this port.
Verify that UFW applied the firewall rules.
The output lists ports 80/tcp and 443/tcp with the ALLOW action.
Create the Docker Compose file.
Add the following configuration:
Save and close the file.
In the above configuration:
discovery.seed_hosts and cluster.initial_cluster_manager_nodes: List all three nodes so the cluster can form on first boot and elect a cluster manager by majority.bootstrap.memory_lock=true: Combined with the memlock ulimit, prevents the Java virtual machine (JVM) heap from swapping to disk.OPENSEARCH_JAVA_OPTS: Sets a fixed 1 GB heap per node, sized for three nodes and Dashboards on an 8 GB server. OpenSearch recommends a heap of about half the memory available to each node, with the rest left for the operating system's file cache. Keep the heap at or below 32 GB, the default upper limit on Amazon OpenSearch Service, so the JVM can keep using compressed object pointers. When you move each node to its own server, raise -Xms and -Xmx together to half of that server's memory.DISABLE_INSTALL_DEMO_CONFIG=true: Stops the image from installing the demo certificates and users.AWS_EC2_METADATA_DISABLED=true: Stops the repository-s3 plugin from querying the AWS instance metadata service, which does not exist outside AWS.127.0.0.1:9200:9200: Publishes the REST API of opensearch-node1 on the loopback interface only. Applications on the same server and the commands in this article can reach it, but other hosts cannot. The Performance Analyzer port 9600 is not published.admin.pem and admin-key.pem: Mounted on opensearch-node1 only, because that is where you run the security administration tool.OPENSEARCH_SSL_VERIFICATIONMODE=full: Makes Dashboards verify each node's certificate and hostname against your certificate authority.Start the stack in detached mode.
Verify that the containers are running.
The output displays running containers for traefik, opensearch-node1, opensearch-node2, opensearch-node3, and opensearch-dashboards.
With the demo configuration disabled, the Security plugin starts uninitialized, without users or roles, and rejects every request until you load the configuration files into the cluster. The security administration tool, securityadmin.sh, loads the files and authenticates with the administrator certificate. Run it again whenever you change a file in the security configuration directory.
Load the security configuration into the cluster.
In the above command:
-cd: The directory that holds internal_users.yml, roles.yml, roles_mapping.yml, and the other security configuration files.-icl: Ignores the cluster name check.-nhnv: Skips hostname verification for the connection to localhost.-cacert, -cert, and -key: The certificate authority, the administrator certificate, and its private key. The output ends with Done with success.
Verify that the admin user can authenticate.
Replace ADMIN_PASSWORD with the password you hashed for the admin user. The output returns JSON with "user_name" : "admin" and all_access in the roles list.
The following checks confirm that the three-node cluster is healthy, that it can accept documents, that the indexed data can be retrieved, and that the REST API is not reachable from other hosts.
Verify cluster health. In this and the following commands, replace ADMIN_PASSWORD with the password of the admin user.
The output returns JSON with "status" : "green" and "number_of_nodes" : 3.
Index a test document.
The output returns JSON with "_index":"test-index", "result":"created", and "_shards":{"total":2,"successful":2,"failed":0}.
Query the document back.
The output returns your document in the hits array, with _source showing "message" : "hello opensearch".
From your workstation or another machine, confirm that the REST API port is closed to the internet.
Replace SERVER_IP with the public IP address of the server. The output reports that the connection was refused or timed out.
Open a web browser and navigate to your Dashboards domain, such as https://dashboards.example.com.
Sign in with the username admin and the password you set for the admin user.
After signing in, you can use OpenSearch Dashboards to search and explore data stored in the cluster, create visualizations and dashboards, and manage users, roles, and index policies from the web interface.
Applications should not connect with the administrator account, which has full access to every index and the security configuration. The Security plugin lets you define a role limited to specific index patterns and actions, then map an internal user to it. The following steps create a role that can create indices with a given name prefix and read and write documents in them, and a user mapped to that role.
Create the role.
In the above command:
cluster_composite_ops: Allows bulk requests, multi-get, multi-search, and alias lookups.crud: Allows reading, writing, and deleting documents in matching indices.create_index: Allows creating matching indices and their mappings. The output returns JSON with "status":"CREATED".
Create the application user.
Replace APP_USER_PASSWORD with a strong password. The output returns JSON with "status":"CREATED".
OpenSearch rejects weak passwords for users created through the REST API, using the zxcvbn password strength estimation library developed by Dropbox. To learn more about zxcvbn, see the Dropbox zxcvbn blog post.
Map the user to the role.
The output returns JSON with "status":"CREATED".
Verify that the application user can write to an allowed index.
The output returns JSON with "result":"created".
Verify that the application user cannot read an index outside its pattern.
The output returns a security_exception error with status 403.
Amazon OpenSearch Service takes automated snapshots for you. On a self-hosted cluster, you register a snapshot repository, a storage location where OpenSearch writes snapshot data, and create a Snapshot Management policy that takes and prunes snapshots on a schedule. The repository uses the S3 repository plugin and the credentials in the keystore to write to your Object Storage bucket.
Register the snapshot repository.
Replace BUCKET_NAME with the name of your Object Storage bucket. OpenSearch verifies that every node can write to the bucket during registration. The output returns {"acknowledged":true}.
Create a Snapshot Management policy that takes a snapshot every day and keeps up to 30 days of snapshots.
In the above command:
creation.schedule: Takes a snapshot at 02:00 UTC every day.deletion.condition: Deletes snapshots older than 30 days or beyond the 30 most recent, while always keeping at least 7.indices: Includes all indices except the Security plugin index. Its configuration comes from the security files in the project directory, so keep a copy of those files with your backups. The output returns JSON with "_id":"daily_snapshots-sm-policy".
Check the policy status.
The output shows the policy as enabled, with the next creation time in the creation section. After the first scheduled run, list the stored snapshots with GET _snapshot/object_storage_repo/_all to confirm that a snapshot reached the bucket.
Amazon OpenSearch Service users often rely on ISM to delete or shrink old indices. The ISM plugin is part of the self-hosted distribution and works the same way. The following policy deletes log indices 30 days after creation, and its ISM template attaches the policy to every new matching index.
Create the ISM policy.
The output returns JSON with "_id":"logs_retention" and the stored policy.
Create a test index that matches the pattern.
The output returns JSON with "acknowledged":true and "index":"logs-test".
Check which policy manages the index.
The output shows "policy_id" : "logs_retention" for the logs-test index.
Adjust the index pattern and the min_index_age value to match your own retention requirements. You can also manage ISM policies in OpenSearch Dashboards by navigating to Index Management.
Amazon OpenSearch Service publishes cluster metrics to Amazon CloudWatch. A self-hosted cluster exposes the same information through its REST API, and the bundled Alerting plugin can watch those values and notify you. OpenSearch splits each index into primary shards and, by default, keeps one replica copy of each primary shard on a different node. Check node resources and disk use regularly, because a node that crosses the low disk watermark stops receiving new shards.
Check heap, memory, CPU, and roles for each node.
The output lists the three nodes with their heap.percent, ram.percent, and cpu values, and marks the elected cluster manager with *. Heap use that stays high across repeated checks indicates that the heap is too small for the workload.
Check disk use and shard counts for each node.
The output lists the shard count, disk used, disk available, and disk percentage for each node.
Review recent log entries from a node when health is not green.
To receive notifications, open OpenSearch Dashboards and navigate to Alerting, then create a per-cluster metrics monitor that checks the cluster health status and sends a message to a notification channel when the status is not green.
Migrating from Amazon OpenSearch Service to a self-hosted cluster is a data and access-control migration rather than an application rewrite, because both sides speak the same REST API.
iam:PassRole permission for the user that registers it, and a SigV4-signed registration request. Take a manual snapshot, copy the snapshot files from the S3 bucket to your Object Storage bucket with a tool such as rclone, register that location on the self-hosted cluster as a repository with "readonly": true, and restore it. Each index must have been created by OpenSearch 2.x or later to restore on OpenSearch 3.x. Reindex indices created by OpenSearch 1.x or Elasticsearch 7.x on an intermediate cluster first. Exclude the Security plugin index .opendistro_security and the Dashboards indices .kibana* from the restore, and set include_global_state to false, so that the restore does not overwrite the users, roles, and saved objects of the new cluster.POST /_reindex using source.remote.host pointed at the Amazon OpenSearch Service endpoint. Add the source host and port to reindex.remote.allowlist in opensearch.yml and restart the nodes, because the setting is static. The remote request authenticates with HTTP basic auth through source.remote.username and source.remote.password, so the source domain needs fine-grained access control with an internal user. Domains that accept only IAM-signed requests reject it. The self-hosted server must also be able to reach the domain endpoint, which rules out VPC-only domains without a network link."index.knn": true) that was migrated to UltraWarm or cold storage on the managed domain, restore it to hot storage on the self-hosted cluster before continuing, because there is no warm or cold tier to migrate it into.POST /_reindex using source.remote.host if you chose the reindex path.GET /INDEX_NAME/_count after the transfer completes.opensearch-node1) for applications running alongside it, or a private network address for applications elsewhere. For remote applications, bind port 9200 to the server's private network address instead of 127.0.0.1, and do not expose it on the public interface.aws-sigv4 interceptors used with the low-level OpenSearch clients) from the application code, because a self-hosted cluster authenticates over standard HTTP basic auth or TLS client certificates instead.root-ca.pem, instead of turning off certificate verification.The following considerations affect the scope and sequencing of an Amazon OpenSearch Service to self-hosted migration.
You have deployed a three-node OpenSearch cluster with OpenSearch Dashboards on Docker Compose, replaced the demo security configuration with your own certificates and users, created a least-privilege application user, scheduled snapshots to Object Storage, added an index retention policy, and verified the deployment end to end. The migration section outlines how to move an existing Amazon OpenSearch Service domain to the self-hosted cluster when a cutover is required. For additional configuration options and API references, see the official OpenSearch documentation.
0 Comments
Be the first to comment and share your perspective with the community.