bcuff / elasticsearch-net-aws

Add-on to Elasticsearch.Net & NEST for using AWS's elasticsearch service.
Apache License 2.0
72 stars 27 forks source link

What are the hard-coded IP & URI constants in InstanceProfileService.cs for? #38

Closed sahilgandhi94 closed 6 years ago

sahilgandhi94 commented 6 years ago

Hey, I was going through the code and found some constants in the code, as copied below:

    private static readonly string[] AliasSeparators = { "<br/>" };
    private const string Server = "http://169.254.169.254";
    private const string RolesPath = "/latest/meta-data/iam/security-credentials/";
    private const string SuccessCode = "Success";

I'm curious as to what the IP address and the URI constants are for?

bcuff commented 6 years ago

EC2 instances are able to access instance metadata using that ip address. See - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html

sahilgandhi94 commented 6 years ago

Is this only limited to ec2 instances? I'm currently struggling to connect to an elasticsearch backend from a Lambda service. It is an authentication issue, but I was hoping I could figure out a way without hardcoding the credentials in my code. Thanks for the help & clarification.

bcuff commented 6 years ago

I believe instance metadata is not available on AWS Lambda. Credentials should come from environment variables. https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html#lambda-environment-variables

If you're using the default credential chain it should try to find credentials via env variables before looking in instance metadata. You could try explicitly using the environment variable provider. Make sure the role you provide to lambda has access to your elasticsearch service cluster.

sahilgandhi94 commented 6 years ago

Awesome. Thanks a bunch.

bcuff commented 6 years ago

you're welcome :)