I'm new in AWS world and try to dev a proof of concept that allow lambda function to interact with elasticSearch (AWS service) and S3 bucket.
I'm not sure to understand really how it works. We have to set an IAM role linked to the Lambda function but no user so first question :
- Who is the user running the Lambda function ?
I set my Elastic Search connexion like this (using https://github.com/DavidMuller/aws-requests-auth) :
def connectES(esEndPoint):
print ('Connecting to the ES Endpoint {0}'.format(esEndPoint))
try:
# let's talk to our AWS Elasticsearch cluster
auth = BotoAWSRequestsAuth(
aws_host='vpc-poc-lambda-3opu7gwdw7bwvtmmazjmdgo7gi.eu-west-3.es.amazonaws.com',
aws_region='eu-west-3',
aws_service='es')
esClient = Elasticsearch(
hosts=[{'host': esEndPoint, 'port': 443}],
use_ssl=True,
verify_certs=True,
connection_class=RequestsHttpConnection,
http_auth=auth)
return esClient
except Exception as E:
print("Unable to connect to {0}".format(esEndPoint))
print(E)
exit(3)
It seams to work but I don't understand what credential it use. Then I create an index successfully with :
esClient.indices.create('test')
But when I try try to index a doc like this I get error :
esClient.index(index='test', doc_type='post', id=123456, body={
'author': 'John Doe',
'blog': 'Learning Elasticsearch',
'title': 'Using Python with Elasticsearch',
'tags': ['python', 'elasticsearch', 'tips'],
})
[WARNING] 2018-02-15T10:39:28.460Z 7f1cc69d-123c-11e8-be8b-cbbfad79068b PUT https://vpc-****-****.eu-west-3.es.amazonaws.com:443/test/post/123456 [status:406 request:0.039s]
Document not indexed
Error: string indices must be integers
I really don't understant why it won't work and hope there is an easy way to interact with other AWS service from Lambda.
Can you help me ? Thanks