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,260 points
2,059 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
• 58,020 points
how to Share this snapshot to another account?
What you can do. Download it from your s3 bucket. And transfer that file into your another s3 bucket in another account. And from there you can upload it.

Related Questions In AWS

0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
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,780 points
1,161 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP