- Newest
- Most votes
- Most comments
Hi bayoojo1,
One cause of "ResourceNotFoundException" could be if the region is set incorrectly on the AWS SDK client if the Lambda function is in another region.
I'm assuming the Timestream database is in eu-west-1 based on the ARN provided. Can you confirm the Lambda function is in eu-west-1? Also, if you are using the AWSK SDK, ensure the SDK client is set to eu-west-1 (this is done automatically if the Lambda function is in eu-west-1).
@tadhg_o, I think the solution is getting closer!
I did as you said by using only the database and table name without the full arn and I got the below error:
Error writing data to Timestream: An error occurred (RejectedRecordsException) when calling the WriteRecords operation: One or more records have been rejected.
Below is the function to write into the timestream db and I guess I'm making a mistake in the format and arrangement. For instance, I want both x_axis and y_axis to be my MeasureValue. Can I include more than one measure value and how do I arrange it?
def write_to_timestream(x_axis, y_axis, total_velocity, device_id, time):
try:
# Format the record
record = {
'Time': time.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3], # Format time as specified
'Dimensions': [{'Name': 'device_id', 'Value': device_id}],
'MeasureName': 'x_axis',
'MeasureValue': str(x_axis),
'MeasureValueType': 'DOUBLE',
'TimeUnit': 'MILLISECONDS'
}
@bayoojo1, glad to hear that fixed the first issue. Unfortunately my Timestream DB knowledge is very limited. Passing in multiple measure values is supported and an example of that in Python can be found here: https://docs.aws.amazon.com/timestream/latest/developerguide/code-samples.write.html#code-samples.write.data.multivalue.
To print out the reason for the rejected error message, you can do something like below:
try: response = timestream.write_records( DatabaseName='TestDB', TableName='TestTable', Records=[record_data] ) print(f"Record written successfully. Result: {response}") except Exception as e: print(f"Error writing record: {e}") for rr in e.response["RejectedRecords"]: print("Rejected Index " + str(rr["RecordIndex"]) + ": " + rr["Reason"])
This will provide you with more details about the error. This snippet of code can be found here: https://docs.aws.amazon.com/timestream/latest/developerguide/code-samples.write.html#code-samples.write.rejectedRecordException
I hope the documentation above is helpful in figuring out the cause for the rejected record!
The ResourceNotFoundException error indicates that the table specified in the Lambda function does not exist in Timestream, even though you can see it through the AWS CLI. Can you check the following ?
- Make sure the IAM role attached to the Lambda function has the necessary permissions to access Timestream. The error suggests it may be missing some permissions.
- Double check that the table ARN specified in the Lambda code exactly matches the ARN of the table when you describe it through the CLI. Even a small difference could cause this error.
- Try running the Timestream WriteRecords API call directly from the CLI using the AWS CLI or SDK instead of through Lambda. This will eliminate Lambda or IAM issues as a potential cause
- Check the CloudWatch logs for the Lambda function for any additional error details. Sometimes a nested cause is provided
- Ensure the database and table specified are in the ACTIVE state and have not been deleted outside of the Lambda function's execution window.
- If the direct API call or CLI command works but not the Lambda function, then it likely points to a permission or configuration issue between Timestream and the IAM role/policy attached to the Lambda function.
Relevant content
- asked a year ago
- asked 7 months ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 months ago
Hi @tadhg_o,
Both the Timestream and the lambda function are in same region - eu-west-1.
@bayoojo1, Are you passing in the full ARN for database and table names? I tested and received the same error when using the full ARN's. When I used just the database and table name, the write_records was successful. Can you test using just the table and database name such as timestreamdb1_table for the table name?
For example, my database is "TestDB" and table name is "DevOpsMulti"
response = timestream.write_records( DatabaseName='TestDB', TableName='DevOpsMulti', Records=[record_data] )