Error in Checking OpenSearch Service for data

1

I am following this tutorial on Creating an Amazon OpenSearch Service Cluster

I followed all the steps till Task 6 which let me check the data. I completed the API test and I got the success message.

Mon Jun 12 18:15:46 UTC 2023 : Received response. Status: 200, Integration latency: 1382 ms

However, I tried heading to the suggested URL with no success.

<FMI>/lambda-s3-index/lambda-type/_search?pretty

Where the <FMI> is the ES domain endpoint

The error is:

{ "error" : "no handler found for uri [/lambda-s3-index/lambda-type/_search] and method [GET]" }

What should I do?

  • I am having the same problem. I think there is a missing step in the tutorial where you integrate a lambda function with Opensearch...

asked a year ago378 views
1 Answer
0

Hello,

I checked the sample code which is available in the document you are following. I can see that code only contains POST API defined for OpenSearch domain and when you trying to search the data its sending a GET request which is not defined in the handler. Hence you are receiving the error "no handler found for uri [/lambda-s3-index/lambda-type/_search] and method [GET]".

Code snippet from document you are following:

def handler(event, context):
    
    sensorID = event['sensorID']
    timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    temperature = event['temperature']
        
    document = { "sensorID": sensorID, "timestamp": timestamp, "temperature": temperature }
    print(document)
    # post to S3 for storage
    s3.put_object(Body=json.dumps(document).encode(), Bucket=bucket, Key=sensorID+"-"+timestamp+".json")
    # post to amazon elastic search for indexing and kibana use
    r = requests.post(url, auth=awsauth, json=document, headers=headers)
    print(r)
    response = "Data Uploaded"
    return {
        "Response" : response,
        "sensorID" : sensorID,
        "temperature": temperature
    }

Next Steps:

In order to mitigate the issue, I will suggest to update your Lambda code and add GET API code in your Lambda handler[1][2] or use POST to send search requests to your Lambda function[3] which will allow you to search data from your OpenSearch domain.

Following documents contain reference codes and you can make changes accordingly in your Lambda function as per your use case:

[1] Tutorial: Creating a search application with Amazon OpenSearch Service - Create the Lambda function - https://docs.aws.amazon.com/opensearch-service/latest/developerguide/search-example.html#sample-lamdba-python

[2] Signing HTTP requests to Amazon OpenSearch Service - Python - https://docs.aws.amazon.com/opensearch-service/latest/developerguide/request-signing.html#request-signing-python

[3] Searching data in Amazon OpenSearch Service - Request body searches - https://docs.aws.amazon.com/opensearch-service/latest/developerguide/searching.html#searching-dsl

AWS
SUPPORT ENGINEER
Rajat_C
answered 10 months ago
  • I tried to replace the POST request with a get request and I still get the same response.

    I tried to print the response returned by both operations inside the lambda function and tested the function. The function logs are: ''' Response { "Response": "Data Uploaded", "sensorID": "0032", "temperature": "356" }

    Function Logs START RequestId: 0b67918d-dbbc-4bcb-9b59-5713ad57afc1 Version: $LATEST {'sensorID': '0032', 'timestamp': '20230617113043', 'temperature': '356'} key: error val: no handler found for uri [/lambda-s3-index/lambda-type] and method [POST] r: <Response [400]>, r2: <Response [400]> key: error val: no handler found for uri [/lambda-s3-index/lambda-type] and method [GET] r: <Response [400]>, r2: <Response [400]> END RequestId: 0b67918d-dbbc-4bcb-9b59-5713ad57afc1 REPORT RequestId: 0b67918d-dbbc-4bcb-9b59-5713ad57afc1 Duration: 664.49 ms Billed Duration: 665 ms Memory Size: 128 MB Max Memory Used: 80 MB Init Duration: 664.59 ms

    Request ID 0b67918d-dbbc-4bcb-9b59-5713ad57afc1 '''

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