<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bens John on Medium]]></title>
        <description><![CDATA[Stories by Bens John on Medium]]></description>
        <link>https://medium.com/@bensjohn21?source=rss-66b42f6d624------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*bqH9Dy3RutPyoq32PJFkcw.jpeg</url>
            <title>Stories by Bens John on Medium</title>
            <link>https://medium.com/@bensjohn21?source=rss-66b42f6d624------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 20:29:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bensjohn21/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AWS ElasticSearch Upgradation]]></title>
            <link>https://medium.com/@bensjohn21/aws-elasticsearch-upgradation-a61b2aed082?source=rss-66b42f6d624------2</link>
            <guid isPermaLink="false">https://medium.com/p/a61b2aed082</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[manual-snapshot]]></category>
            <category><![CDATA[aws-elasticsearch]]></category>
            <category><![CDATA[elastic-search-upgrade]]></category>
            <dc:creator><![CDATA[Bens John]]></dc:creator>
            <pubDate>Wed, 18 Sep 2019 12:10:22 GMT</pubDate>
            <atom:updated>2019-09-23T12:11:53.956Z</atom:updated>
            <content:encoded><![CDATA[<p>This is for the users who wants to upgrade their AWS ElasticSearch to a newer version without any downtime. This process is recommended in a production environment. This story also explains the basics methods create an AWS ElasticSearch. This is going to little long, but I promise to be precise and to the point. Good luck !!</p><p>I am assuming you to have some prior knowledge on AWS Console, AWS ElasticSearch (represented as ES anymore), AWS S3, IAM Roles, Policies etc.</p><p>Now, When it comes to Upgrading a managed ES, there are two ways of doing it.</p><ol><li>Upgrade from the AWS Console</li><li>Create a upgraded version ES and migrate old indices to the new one.</li></ol><p>Talking about the first point in brief, Login to AWS Console, Go to ES dashboard, Click on your current ES and you get a tab to Upgrade, Click on Upgrade and you are good to go.</p><p>By default, AWS takes a snapshot before upgrading. However, it is recommended for you to take a manual snapshot and store it in S3. Steps for this will be explained in the later part or you can directly jump in <a href="https://medium.com/p/a61b2aed082#8170">here</a>.</p><p>**Note: <em>The above process requires downtime of more than 15 minutes, this is not recommended in a Production Environment.</em></p><p>For a zero downtime upgrade, I recommend you to go with the second point and this is what I am mainly focusing on in this document.So lets start.</p><p>The approach is to basically create a new updated ES domain and migrate indices from old ES domain to the new one. Lets take it step by step.</p><h3>Create a new ES Domain</h3><p>Login to AWS console, Go to ES Dashboard, Find the tab to create new domain, Select the desired version and make sure you enter the same configurations(vpc, subnet, etc) as the old ES, Click on Create Domain. It takes few minutes to create it. Once the domain status is Active, click on the domain name and record its Endpoint and ARN name, We will need it later.</p><h3>Migrate indices from old ES domain to the new one</h3><p>Lets break the second step furthermore. This means take manual snapshot of the current ES domain and store it in S3, later restore the stored indices from S3 to new ES domain. Now, Lets take this step by step.</p><h4>Take manual snapshots of the current ES domain</h4><p>By default AWS ES stores snapshot in stored S3 bucket. As we do storing and restoring through the same bucket, we will need to register both the domains with the bucket.</p><p>We must first <a href="https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html"><strong>create a S3 bucket</strong></a>, Make a note of the bucket’s name. We need it later. For Ex: snapshot-bucket (arn:aws:s3:::snapshot-bucket)</p><p>Next step<strong>, create a Role</strong>, The trust relationship for the role must specify Amazon Elasticsearch Service in the Principal statement.</p><pre>{<br>   &quot;Version&quot;: &quot;2012-10-17&quot;,<br>   &quot;Statement&quot;: [{<br>     &quot;Sid&quot;: &quot;&quot;,<br>     &quot;Effect&quot;: &quot;Allow&quot;,<br>     &quot;Principal&quot;: {<br>       &quot;Service&quot;: &quot;es.amazonaws.com&quot;<br>     },<br>     &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>   }]<br> }</pre><p>Lets say we created a Role called TheSnapshotRole</p><p>Next, <strong>create IAM policy</strong>, To create this IAM policy, open the IAM console, switch to the Policies tab, and choose Create Policy. Select Create Your Own Policy, and give your policy a name. Ex : ESBackup-policy</p><p>Attach the following permissions</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;VisualEditor0&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;iam:PassRole&quot;,<br>                &quot;s3:ListBucket&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;arn:aws:iam::YOUR-ACCOUNT-ID:role/TheSnapshotRole&quot;,<br>                &quot;arn:aws:s3:::snapshot-bucket&quot;<br>            ]<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;VisualEditor1&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;s3:PutObject&quot;,<br>                &quot;s3:GetObject&quot;,<br>                &quot;s3:DeleteObject&quot;<br>            ],<br>            &quot;Resource&quot;: &quot;arn:aws:s3:::snapshot-bucket/*&quot;<br>        },<br>        {<br>            &quot;Sid&quot;: &quot;VisualEditor2&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: &quot;es:ESHttpPost&quot;,<br>            &quot;Resource&quot;: [<br>                            &quot;arn:aws:es:region:YOUR-ACCOUNT-ID:domain/YOU-OLD-ELASTIC-SEARCH-DOMAIN-NAME&quot;,<br>                            &quot;arn:aws:es:region:YOUR-ACCOUNT-ID:domain/YOU-NEW-ELASTIC-SEARCH-DOMAIN-NAME&quot;<br>                        ]<br>        }<br>    ]<br>}</pre><p><em>** NOTE: The last part of the above policy statement, we have added our new domain also as a Resource, that way we can reuse this policy and role while restoring indices from S3 bucket.</em></p><p><em>** NOTE: Above ARNs I used are from the example I mentioned before. Make sure you change the bucket ARNs.</em></p><p>Next step,<strong> register the repository</strong></p><p>We must register a snapshot repository with ES 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. You use Elasticsearch’s _snapshot API action to register a repository with Amazon ES.</p><pre># Create the python file to register the repo<br>cat &gt;/tmp/register-repo.py &lt;&lt;&quot;EOF&quot;<br>import boto3<br>import requests<br>from requests_aws4auth import AWS4Auth<br> <br>host = &#39;OLD_DOMAIN_END_POINT&#39; <br>#Do it for new domain also.</pre><pre>region = &#39;us-west-2&#39;<br>service = &#39;es&#39;<br>credentials = boto3.Session().get_credentials()<br>awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)<br> <br># Register repository<br>path = &#39;_snapshot/my-snapshot-repo&#39; # the Elasticsearch API endpoint<br>url = host + path<br> <br>payload = {<br>  &quot;type&quot;: &quot;s3&quot;,<br>  &quot;settings&quot;: {<br>    &quot;bucket&quot;: &quot;elasticsearch-backup-indices&quot;,<br>    &quot;region&quot;: &quot;us-west-2&quot;,<br>    &quot;role_arn&quot;: &quot;arn:aws:iam::YOUR-ACCOUNT-ID:role/TheSnapShotRole&quot;<br>  }<br>}<br> <br>headers = {&quot;Content-Type&quot;: &quot;application/json&quot;}<br> <br>r = requests.put(url, auth=awsauth, json=payload, headers=headers)<br> <br>print(r.status_code)<br>print(r.text)<br>EOF</pre><p><em>** NOTE: if your S3 bucket resides in different region make sure, you mention the same in the script.</em></p><pre># Execute the file to register repo<br>chmod 700 /tmp/register-repo.py<br>python /tmp/register-repo.py</pre><p>Output should be</p><pre>200<br>{&quot;acknowledged&quot;:true}</pre><p>Now , We need to register the new ES Domain again with this repository, change the HOST variable in python file and execute it again.</p><p>Lastly, <strong>take the snapshot</strong></p><p>Once you have your repository set up, you use the _snapshot API action to create a snapshot of your index. By default, Amazon ES snapshots the entire cluster’s indexes</p><p>You specify two pieces of information when you create a snapshot:</p><ul><li>Name of your snapshot repository — Ex: my-snapshot-repo</li><li>Name for the snapshot — Ex: 2019–01–19</li></ul><pre>curl -XPUT &#39;elasticsearch-domain-endpoint/_snapshot/repository/snapshot-name&#39;<br>Ex:curl -XPUT &#39;https://OLD_ES_DOMAIN-ENDPOINT/_snapshot/my-snapshot-repo/2019-01-19&#39;</pre><p>You should get message after the above command</p><pre>{“accepted”:true}</pre><p><em>** NOTE: Snapshots are not instantaneous; they take some time to complete.</em></p><p>Use the following command to verify the state of snapshots of your domain:</p><pre>curl -XGET ‘https://OLD_ES_DOMAIN-ENDPOINT/_snapshot/my-snapshot-repo/_all?pretty&#39;</pre><h4>Restore indices from Snapshot</h4><p>To restore, you must ensure that the index is not open. This state is normally the case if you are reloading old data into the same cluster. If the index is open, delete the existing index first, then restore your backup.</p><p>When you restore, you specify the snapshot, and also any indexes that are in the snapshot. You do this in much the same way as when you took the snapshot in the first place.</p><pre>curl -XPOST &#39;<a href="https://search-mb-production-app.us-west-2.es.amazonaws.com/_snapshot/my-snapshot-repo/2019-01">https://search-mb-production-app.us-west-2.es.amazonaws.com/_snapshot/my-snapshot-repo/2019-01</a>–19/_restore&#39; -d&#39;{<br>  &quot;indices&quot;: &quot;alb-accesslog-2018-08-28&quot;,<br>  &quot;ignore_unavailable&quot;: false,<br>  &quot;include_global_state&quot;: false<br>}&#39; -H &#39;Content-Type: application/json&#39;</pre><p>You should get message after the above command</p><pre>{“accepted”:true}</pre><p>Once Done, We can verify if the number of searchable documents in new ES domain is equal to that in old ES domain.</p><p>Problems Faced.</p><pre><strong><em>The User is not Authorized to perform ESHttpPut / ESHttpPost</em></strong> :<br>Check if the ARNs  are correctly mentioned inside the access policy.<br>Check the Access policy of the domain.<br>Check the user creds (Try listing s3 resources).</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a61b2aed082" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>