The error: “no permissions for [indices:data/read/search/template]” was driving me crazy.
While working with AWS Lambda and OpenSearch, I recently stumbled upon an interesting challenge related to permissions. Specifically, when trying to use Lambda to interact with an OpenSearch index, even after configuring the correct IAM role, I faced unexpected access issues.
After some troubleshooting, I discovered a solution, which I’m excited to share in case you encounter similar issues. Here’s how I solved the problem:
The Permissions Problem
When interacting with OpenSearch from a Lambda function, specific permissions are required for the requests to succeed. For example, when writing, updating, or deleting documents in an OpenSearch index like “test-index”, your IAM role must have the following OpenSearch permissions:
indices:data/write/bulk*
indices:data/write/delete
indices:data/write/index
indices:data/write/update
These permissions allow Lambda to perform essential actions like adding, updating, or deleting documents in your OpenSearch index. For example, operations such as:
PUT test-index/_doc/tt0816711
These permissions govern the core OpenSearch actions, and they go beyond specific API paths or HTTP methods. Essentially, they cover the underlying OpenSearch actions required for document manipulation.
The IAM Role Challenge
With this understanding, I thought I could solve the issue by giving the appropriate permissions in my Lambda function’s IAM role. So, I configured an IAM role with the following policy:
{
"Version": "2012–10–17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"es:*"
],
"Resource": "*"
}
]
}
This configuration grants broad access to OpenSearch, allowing any action (via “es:*”`) on any resource (via “Resource”: “*”) within my AWS account. However, despite having this generous policy in place, I still encountered permission-related errors.
The Missing Piece: Backend Roles and User Mappings
The key discovery was that IAM roles alone aren’t enough when dealing with OpenSearch in this scenario. You also need to ensure that your OpenSearch domain has proper role mappings and user mappings. This requires the following:
1. Mapping Backend Roles to OpenSearch Roles: Even with an IAM role configured, you need to map this role to your OpenSearch role. This essentially connects the AWS IAM role with permissions inside OpenSearch itself.
2. Create or Duplicate Roles in OpenSearch: OpenSearch has its own internal roles (e.g., “all_access“). You may need to create or map a new role that has the necessary permissions to perform the operations Lambda is trying to execute.

Here’s how I mapped my IAM roles to OpenSearch roles:
Backend Role Mapping
In OpenSearch, I mapped the following backend roles:
– arn:aws:iam::XXXXXXXXX:role/aws-reserved/sso.amazonaws.com/XXXXXXXXX
– arn:aws:iam::XXXXXXXXX:role/service-role/LAMBDA_ROLE-XXXXXXXXX
Both roles were mapped to the “all_access” role within OpenSearch, granting them the necessary permissions.
User Mapping
Additionally, I mapped my user type, “admin”, which allows full access to the OpenSearch index. This step is essential for Lambda to be able to add, update, and delete documents effectively, without running into permission issues.
Conclusion
Working with OpenSearch from Lambda can involve more than just IAM roles. In addition to configuring your Lambda function with the correct IAM policies, you need to ensure that:
– Your IAM roles are mapped to OpenSearch roles.
– You assign the appropriate backend roles within OpenSearch.
– You ensure that the OpenSearch roles (e.g., “all_access”) have sufficient permissions.
By mapping these roles properly, I was able to resolve the access errors I encountered, allowing my Lambda function to perform the intended operations in OpenSearch. If you’re facing similar permission issues, I hope this post provides the solution you need!
Feel free to drop any questions or thoughts in the comments.