aws-samples / bedrock-claude-chat

AWS-native chatbot using Bedrock + Claude (+Mistral)
MIT No Attribution
908 stars 324 forks source link

[BUG] Lambda Function "OpenSearchIndexCRProvide" Fails to Import opensearch_index Module - ModuleNotFoundError #588

Closed ManhNguyenNG closed 1 week ago

ManhNguyenNG commented 2 weeks ago

🚨 Please Note 🚨

To ensure efficient investigation of the issue, please fill out the fields below with as much detail as possible. Reports that do not follow this template may be closed without notification. We appreciate your cooperation.

Describe the bug

The Lambda function fails to import the opensearch_index module, resulting in a "No module named 'opensearch_index'" error. This prevents the function from executing correctly, as it relies on opensearch_index to connect to OpenSearch. As a result the bot is always syncing without result.

image

To Reproduce

Steps to reproduce the behavior:

  1. Deploy the stack
  2. Trigger the Lambda function by creating a new bot in Bot Console
  3. Observe the logs for any error messages in cloudwatch
  4. See error

Screenshots

image

Additional context

This issue may be related to the Lambda deployment package or missing dependencies. The code attempts to import connect_opensearch from the opensearch_index module, which seems to be unavailable in the current environment. We are using a custom resource to create, update, and delete VPC endpoints with OpenSearch, and this error prevents the resource from functioning as expected.

statefb commented 2 weeks ago

Which version of @cdklabs/generative-ai-cdk-constructs are you using? (It can be referred on cdk/package.json)

ManhNguyenNG commented 2 weeks ago

Hi, the version used is : "@cdklabs/generative-ai-cdk-constructs": "^0.1.274"

statefb commented 2 weeks ago

It seems the same version as used in the latest of bedrock-claude-chat. It does not happen on my environment, could you provide more detail to repuroduce?

typex1 commented 2 weeks ago

I can confirm to have the exact same error situation. All bots stay in the "Syncing" state forever.

More details:

@ingestionTime
1730989857672 @log
527704779651:/aws/lambda/BrChatKbStack01JC3GA548P8-OpenSearchIndexCRProvide-b5fLuVHmhdS8 @logStream
2024/11/07/[$LATEST]3702b43d90024f53bb415b3e9eb97524 @message
[ERROR] 2024-11-07T14:30:48.654Z No module named 'opensearch_index' Traceback (most recent call last): File "/var/task/custom_resources/init.py", line 28, in from .opensearch_vpc_endpoint import on_event as on_event_opensearch_vpc_endpoint File "/var/task/custom_resources/opensearch_vpc_endpoint.py", line 31, in from opensearch_index import connect_opensearch ModuleNotFoundError: No module named 'opensearch_index' @timestamp
1730989848655

The only thing in my deployment which might be different from a standard one: the stack is not deployed in us-east-1, but in eu-central-1. I am happy to share more details if needed!

typex1 commented 1 week ago

This solved the problem for me: I checked the Step Functions workflow, and it failed. Reason: I had not given access to the needed embedding model. Snippet from Step Functions step "StartIngentionJob", state output: "[...] not able to call specified bedrock embedding model arn:aws:bedrock:eu-central-1::foundation-model/amazon.titan-embed-text-v2:0: You don't have access to the model with the specified model ID.".

Needed further steps: