- Newest
- Most votes
- Most comments
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
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 '''
Relevant content
- asked 2 years ago
- Accepted Answerasked 9 months ago
- asked a year ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 9 months ago
I am having the same problem. I think there is a missing step in the tutorial where you integrate a lambda function with Opensearch...