aws-sdk-js-v3: TimestreamQueryClient.query throws UnknownOperationException

Describe the bug Trying to query a Timestream table using TimestreamQueryClient results in UnknownOperationException.

SDK version number @aws-sdk/client-timestream-query@^3.2.0

Is the issue in the browser/Node.js/ReactNative? Node.js

Details of the browser/Node.js/ReactNative version

$ node -v
v12.16.1

To Reproduce (observed behavior)

const {TimestreamQueryClient, QueryCommand} = require('@aws-sdk/client-timestream-query')
const client = new TimestreamQueryClient({region: 'us-east-2'})
const command = new QueryCommand({QueryString: 'SELECT * FROM table'})
await client.send(command)

or

const {TimestreamQuery} = require('@aws-sdk/client-timestream-query')
const client = new TimestreamQuery({region: 'us-east-2'})
await client.query('SELECT * FROM table')

Expected behavior No error.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 10
  • Comments: 17 (3 by maintainers)

Most upvoted comments

To me it looks like the SDK is not correctly resolving the endpoint. This still happens in v3.5.0 for simple commands.

The docs state that the endpoint resolution is done automatically but the 404 indicates this is not true or not working correctly.

The following code solves the issue for me, it also requires the timestream:DescribeEndpoints permission (the fallback url ingest-cell1.timestream.eu-west-1.amazonaws.com was determined by calling the DescribeEndpoint command):

const getWriteClient = async ({defaultRegion: fallbackRegion}: { defaultRegion: string } = { defaultRegion: 'eu-west-1'}): Promise<TimestreamWriteClient> =>
	new TimestreamWriteClient({})
		.send(new DescribeEndpointsCommand ({}))
		.then(
			({Endpoints}) =>
				new TimestreamWriteClient({
					endpoint: `https://${ Endpoints?.[0].Address ?? `ingest-cell1.timestream.${fallbackRegion}.amazonaws.com` }`,
				}),
		)
// Get the region from the env.AWS_REGION
const timestreamWriteClient = await getWriteClient({ defaultRegion: 'eu-west-1'})

Does this have to do something with : https://github.com/aws/aws-sdk-js-v3/pull/1643/commits/cba38d3c199893c625798225184e1d04afec4cdb ?

I’m also hitting the same issue

The endpoint discovery is not yet supported in AWS SDK for JavaScript (v3). This documentation is currently in PR https://github.com/aws/aws-sdk-js-v3/pull/2106, and the support is planned in 2021.

I encountered this same generic error on writeRecords. However, after downgrading to AWS-SDK v2 and using the exact same inputs writeRecords worked fine.

export const buildTimestreamWrite = (d) => {
  return {
    "CommonAttributes": {
       "Dimensions": dimensions.map(name => ({
            "DimensionValueType": "VARCHAR",
            "Name": name,
            "Value": `${d[name]}`,
        })),
       "Time": `${d[timestamp]}`,
       "TimeUnit": "MILLISECONDS",
    },
    "DatabaseName": tsDatabase,
    "Records": numericValues.map(name => ({
      "MeasureName": name,
      "MeasureValue": `${d[name]}`,
      "MeasureValueType": "DOUBLE",
    })),
    "TableName": dataSetSuffix
 }
}

V2 code that works:

import { TimestreamWrite } from 'aws-sdk';
const tsClient = new TimestreamWrite({ region: "us-west-2" });
const tsRequests = (<any[]>rawBatch).map(buildTimestreamWrite);
const batchPromises = tsRequests.map(command => tsClient.writeRecords(command).promise());
try {
  console.log(await Promise.all(batchPromises));
} catch (error) {
  console.log(error);
}

V3 code that does not work:

import { TimestreamWrite } from "@aws-sdk/client-timestream-write";
const tsClient = new TimestreamWrite({ region: "us-west-2" });
const tsRequests = (<any[]>rawBatch).map(buildTimestreamWrite);
const batchPromises = tsRequests.map(command => tsClient.writeRecords(command));
try {
  console.log(await Promise.all(batchPromises));
} catch (error) {
  console.log(error);
}

My error:

UnknownOperationException: UnknownOperationException
    at deserializeAws_json1_0WriteRecordsCommandError (<root>/node_modules/@aws-sdk/client-timestream-write/protocols/Aws_json1_0.ts:1644:39)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at <root>/node_modules/@aws-sdk/middleware-serde/src/deserializerMiddleware.ts:20:18
    at <root>/node_modules/@aws-sdk/middleware-signing/src/middleware.ts:26:22
    at StandardRetryStrategy.retry (<root>/node_modules/@aws-sdk/middleware-retry/src/defaultStrategy.ts:125:38)
    at <root>/node_modules/@aws-sdk/middleware-logger/src/loggerMiddleware.ts:21:20
    at async Promise.all (index 0)
    at loadData (<root>/src/import-ts.ts:128:23) {
  __type: 'com.amazon.coral.service#UnknownOperationException',
  '$fault': 'client',
  '$metadata': {
    httpStatusCode: 404,
    requestId: '30708119-3588-49e5-b2bd-fb9c60dfbdd0',
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  }
}

@trivikr @kennu Tried the above mentioned workaround and it did not work as expected. Are there any other workarounds/solutions?