AWS SDKs & Accessing Timestream
We can use the AWS SDK to access Timestream outside of the console - ie. to serve the data so that the dashboard team is able to get and display data for the dashboard. Specifically, Timestream supports two SDKS: the Write SDK and the Query SDK (see Using the AWS SDKs ).
Write SDK
- used to perform CRUD operations
- insert timeseries data into Timestream
Query SDK
- query existing data that is already stored in Timestream
Installing the AWS JS SDK
We used the node.js SDK in this iteration, but there are other SDKs available in different languages. Timestream documentation provides a link to this sample repo with a working sample. A barebone repo with just the code required for the EMA project can also be found on github - link here. For both examples, ensure that you have configured your AWS Credentials (links below).
The general steps are listed below, with links to the detailed AWS documentation pages.
- Install node if not yet installed
- In a new node.js app, install the AWS SDK for JS with your preferred package manager.
- Installing AWS JS SDK Documentation
- For example, with npm:
- Configure AWS Credentials
- Getting your AWS Credentials (*note: this link leads to an older v2 of the SDK, but worked for our sample)
- Loading your AWS Credentials
- Create Package.json as needed (or just install the required packages if using samples)
- Write the node.js code, which includes the new instances of the Timestream clients for both Write and Query SDKs, SQL queries to query the specific data you’re looking for, and the code to use the functions provided by the SDKs to retrieve data from the database (docs).