AWS OpenSearch Serverless - returning 403 error with correct access policy

0

I’m trying to create a REST API on my lambda to create a document within my opensearch serverless collection.

I’m able to do this manually through the dashboard. However, while trying to hit the endpoint I’m getting 403 errors.

I have granted all access on my access policy and followed the tutorial and even this re:Post article (https://repost.aws/questions/QU32hRu7KtQd-XWauqWXMjqQ/opensearch-serverless-javascript-content-length-403-error) but still no luck.

Any help would be greatly appreciated.

1 Answer
4
Accepted Answer

Assuming your data access policy is configured properly, make sure your Lambda function's execution role has aoss:APIAccessAll permissions applied for data-plane access, see Using data-plane policies

AWS
answered 10 months ago
  • I have added those into my IAM but still getting a 403 error.

    Heres a snippet of my data access policy: policy = jsonencode([{ "Rules" : [ { "ResourceType" : "index", "Resource" : [ "index/my-data-collection-${var.stage}/*" ], "Permission" : [ "aoss:CreateIndex", "aoss:ReadDocument", "aoss:UpdateIndex", "aoss:WriteDocument", "aoss:*" ]}], "Principal" : [ "arn:${partition}:iam::${account_id}:user/${stage}"]

    And a snippet of my IAM: `iamRoleStatements:

    • Effect: Allow Action:
    • aoss:APIAccessAll Resource:
    • arn:aws:aoss:${aws:region}:${aws:accountId}:collection/id`
  • Is that the full data access policy? If so, you will need to add the ARN of the Lamaba function's execution role to the Principal element.

    For example

    policy = jsonencode([
    { 
        "Rules" : [{
            "ResourceType" : "index", 
            "Resource" : [ 
                "index/my-data-collection-${var.stage}/*" ], 
                "Permission" : [ 
                        "aoss:CreateIndex",
                        "aoss:ReadDocument",
                        "aoss:UpdateIndex",
                        "aoss:WriteDocument",
                        "aoss:*"
                  ]
          }], 
          "Principal" : [
                "arn:${partition}:iam::${account_id}:user/${stage}",
                "arn:${partition}:iam::${account_id}:role/${LambdaExecutionRoleName}"
           ]
    

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.

Guidelines for Answering Questions