Is there a way to move AWS Elasticsearch to another account

0 votes
I've found ways to move EC2 and RDS into another account.

I'm moving all the instances under each service from old AWS account into new AWS account.

Now I am trying to move Elasticsearch from old account to the new one.

I couldn't able to figure out a way to move my Elasticsearch.

Can anyone help me on this?
Oct 30, 2018 in AWS by findingbugs
• 3,140 points
52 views

1 answer to this question.

0 votes

Create a role with Elasticsearch permission.

Provide the iam:PassRole for the iam user whose access/secret keys will be using to take snapshot.

{
  "Version": "2012-10-17",
  "Statement": {
    "Effect": "Allow",
    "Action": "iam:PassRole",
    "Resource": "arn:aws:iam::accountID:role/TheServiceRole"
  }
}

Change the access & secret key, host, region, path, and payload in the below code and execute it.

import requests
from requests_aws4auth import AWS4Auth

AWS_ACCESS_KEY_ID=''
AWS_SECRET_ACCESS_KEY=''
region = 'us-west-1'
service = 'es'

awsauth = AWS4Auth(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, region, service)
host = 'https://elasticsearch-domain.us-west-1.es.amazonaws.com/' # include https:// and trailing /

# REGISTER REPOSITORY
path = '_snapshot/my-snapshot-repo' # the Elasticsearch API endpoint
url = host + path

payload = {
  "type": "s3",
  "settings": {
    "bucket": "s3-bucket-name",
    "region": "us-west-1",
    "role_arn": "arn:aws:iam::accountID:role/TheServiceRole"
  }
}

headers = {"Content-Type": "application/json"}
r = requests.put(url, auth=awsauth, json=payload, headers=headers) # requests.get, post, put, and delete all have similar syntax
print(r.text)

Take the snapshot and store it in the S3

path = '_snapshot/my-snapshot-repo/my-snapshot'
url = host + path
r = requests.put(url, auth=awsauth)
print(r.text)

Share this snapshot to another account and use the same code with new account keys and endpoint to restore it using the below code snippet.

To restore all indices from the snapshot

path = '_snapshot/my-snapshot-repo/my-snapshot/_restore'
url = host + path
r = requests.post(url, auth=awsauth)
print(r.text)

To restore single index from the snapshot

path = '_snapshot/my-snapshot-repo/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)

Reference: AWS docs.

answered Oct 30, 2018 by Priyaj
• 56,520 points

Related Questions In AWS

0 votes
1 answer
+2 votes
2 answers

How do we move a domain from Hostgator to AWS Route 53?

I found this  Before transferring a domain, make ...READ MORE

answered Aug 3, 2018 in AWS by Priyaj
• 56,520 points
878 views
0 votes
1 answer

Quick way to get AWS Account number from the cli tools?

Via "Secure Token Service" using the following ...READ MORE

answered Jul 12, 2018 in AWS by Priyaj
• 56,520 points
69 views
0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers

Is there a API to get AWS Marketplace Products

AWS Marketplace Entitlement Service API Reference The AWS ...READ MORE

answered Aug 1, 2018 in AWS by findingbugs
• 4,750 points
80 views