Skip to content

EC2 connecting to AWS Opensearch

0

While trying to connect Logstash (running on an EC2 instance in a private subnet) to AWS OpenSearch (also in a private subnet within the same VPC), I encountered the following error during a curl request to the domain endpoint:

"User: anonymous is not authorized to perform: es:ESHttpGet because no resource-based policy allows the es:ESHttpGet action."

asked a year ago367 views

1 Answer
0

This error occurs because your EC2 instance doesn't have the proper authorization to access your OpenSearch domain, even though both are in the same VPC. There are several ways to resolve this issue:

  1. Resource-based policy: You need to create a resource-based policy for your OpenSearch domain that allows access from your EC2 instance. The policy should grant the necessary permissions (like es:ESHttpGet) to the IAM role or user that your EC2 instance is using.

  2. IAM role for EC2: Ensure your EC2 instance has an IAM role attached with permissions for OpenSearch operations (es:ESHttpGet and potentially es:ESHttpPost if you'll be using features like the Discover page).

  3. IP-based access control: If you're using a proxy server between your application and OpenSearch, you can set up an IP-based access policy that allows requests from the proxy's IP address.

  4. Fine-Grained Access Control (FGAC): For more granular control, you can enable FGAC on your OpenSearch domain and create roles that allow specific access to indices and operations.

For your specific error, you need to create a resource-based policy that allows the EC2 instance's IAM role to perform es:ESHttpGet actions on your OpenSearch domain. Here's what a sample policy might look like:

{
"Version": "2012-10-17",
"Statement": [
{
"Resource": "arn:aws:es:region:account-id:domain/domain-name/*",
"Principal": {
"AWS": "arn:aws:iam::account-id:role/your-ec2-role"
},
"Action": [
"es:ESHttpGet",
"es:ESHttpPost"
],
"Effect": "Allow"
}
]
}

Note that for using OpenSearch Dashboards' Discover page, you'll need to include es:ESHttpPost permission as well, since the Discover page uses POST requests even for read-only operations.
Sources
Using OpenSearch Dashboards with Amazon OpenSearch Service - Amazon OpenSearch Service
OpenSearch UI dashboard's Discover page requires ESHttpPost permission even when you only want to grant read access | AWS re:Post

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.