I am writing AWS Elasticsearch snapshots backup/restore implementation using python boto. I was able to register AWS S3 as ES snapshots repository. Here is the snippet of my create snapshots function.
import boto
import urllib
from boto.connection import AWSAuthConnection
class ESConnection(AWSAuthConnection):
def __init__(self, region, **kwargs):
super(ESConnection, self).__init__(**kwargs)
self._set_auth_region_name(region)
self._set_auth_service_name("es")
def _required_auth_capability(self):
return ['hmac-v4']
def create_snapshots(profile, region_name, es_host,total_snapshots_to_keep):
.
.
.
url = "/_snapshot/es_repository/{}?".format(snapshot_name)
flag = urllib.urlencode({'wait_for_completion':'true'})
resp = client.make_request(method='PUT',
path=urllib.quote("{}{}".format(url,flag)),
data='{"indices": "' + audit_index_name + '", "ignore_unavailable": true, "include_global_state": false}')
Main problem seems to be in above snippet where I am trying to construct an url for
{u'status': 400, u'error': {u'root_cause': [{u'reason': u'[es_repository:v4_2017_03_27_snapshot?wait_for_completion=true] Invalid snapshot name [v4_2017_03_27_snapshot?wait_for_completion=true], must not contain the following characters [\, /, *, ?, ", <, >, |, , ,]', u'type': u'invalid_snapshot_name_exception'}], u'type': u'invalid_snapshot_name_exception', u'reason': u'[es_repository:v4_2017_03_27_snapshot?wait_for_completion=true] Invalid snapshot name [v4_2017_03_27_snapshot?wait_for_completion=true], must not contain the following characters [\, /, *, ?, ", <, >, |, , ,]'}}
It is taking my actual snapshot_name and wait_for_completion flag entirely as a snapshot name
Invalid snapshot name [v4_2017_03_27_snapshot?wait_for_completion=true], must not contain the following characters [\, /, *, ?, ", <, >, |, , ,]'}}
Could you please help me pointing out place where I am doing it wrongly in constructing url for elasticsearch? Or is there any better way to accomplish this?