Run of Queries in Amazon Timestream Database for LiveAnalytics
Tags: aws, amazontimestream, amazons3, sns
Published: 2024-07-14 09:35:04

“ I have checked the documents of AWS to run the queries in amazon timestream database for liveanalytics. Amazon timestream service provides a query editor where we can directly select the database and table created in timestream db and be able to run the queries in it. Pricing of the solution depends on usage of timesteam db, s3 bucket and sns service.”

Amazon Timestream for LiveAnalytics is a fast, scalable, fully managed, purpose built time series database that makes it easy to store and analyze trillions of time series data points per day. Timestream for LiveAnalytics saves you time and cost in managing the lifecycle of time series data by keeping recent data in memory and moving data to a cost optimized storage tier based upon user defined policies. 

Timestream for LiveAnalytics' built query engine lets you access and analyze recent and data together, without having to specify its location. It built in time series analytics functions, helping you identify trends and patterns in your data in near real time. It is serverless and automatically scales up or down to adjust capacity and performance. Because you don't need to manage the underlying infrastructure, you can focus on optimizing and building your applications.

In this post, you will get to know how to run the queries in amazon timestream database for liveanalytics. Here I have used a sns topic and s3 bucket.

#Prerequisites
You’ll need an Amazon SNS for this post. [Getting started with amazon SNS](https://aws.amazon.com/sns/getting-started/) provides instructions on how to create a topic and subscription. For this blog, I assume that I have a sns topic created.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szudu2aefgomva6riv0z.png)
The architecture diagram shows the overall deployment architecture with data flow, amazon timestream, sns topic, s3 bucket, query editor and mail box.

#Solution overview
The blog post consists of the following phases:
1. Create Database in Amazon Timestream for LiveAnalytics
2. Create Database and Table with Custom Options
3. Schedule of Query for Database and Table with SNS Notification

I have sns topic with subscription as below →
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhpivu0gcltqiz5f42zf.png)

##Phase 1: Create Database in Amazon Timestream for LiveAnalytics
1. Open the Timestream console and create a database with configurations as sample database named “TestDB”, datasets as IOT and DevOps, multi-measure records option. Also test the sample database with sample queries in query editor. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ne1abu0dysh8taozbp38.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k07ifusmv1zbsheaemcq.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s3yd8eithzwaizh1eh4w.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dbmigvnmsr290uw6qjy2.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yjphavoypxo4sp2806xx.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7sg5b3nav0oe4onsj5oo.png)

##Phase 2: Create Database and Table with Custom Options
1. In timestream, create a database as a standard database with aws managed encryption option. Also create a table with a custom partition key and data retention option. Also test of database and table in query editor with run of query.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwjibez5yntbqu4qkqf0.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/55i4z1f9g464q131935a.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y765er19uour8ju96hz6.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8v5xvqptmz5pcpgu7c5x.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzylxp95vo7dvxg859k8.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gb2fw94brnvsehg24u9.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wuyojexft7uugq145a5g.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0vr9pp6sirbuffd76xpi.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p3zwaf7d4u64c37knhsw.png)

##Phase 3: Schedule of Query for Database and Table with SNS Notification

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g86tcmebjpfa31j1t3ds.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uscv6wiildefn745ei3w.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6x9j3u486sdazetch83.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rb0daul24h31q1dvbmwo.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y8hot9hurhbz5m41o7uf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajle64b9r5rycbadxkmj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qp05kqhd4oxg8jdjo31y.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d4aqlogk1hf4i91cnuyn.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gppj4as0v9zq2jcc7bje.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zu44ibfmwnmqwugp6nie.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0lno9wp8yq2t27duvcri.png)

#Clean-up
Delete SNS Topic, S3 Bucket and Timestream.

#Pricing
I review the pricing and estimated cost of this example. 

Cost of Simple Notification Service = Free for notifications and requests = $0.0

Cost of Amazon Timestream = $0.0

Cost of S3 = $0.25

Total Cost = $0.25

#Summary
In this post, I showed “how to run the queries in amazon timestream database for liveanalytics”.

For more details on Amazon Timestream, Checkout Get started Amazon Timestream, open the [Amazon Timestream console](https://us-east-1.console.aws.amazon.com/timestream/home?region=us-east-1#welcome). To learn more, read the [Amazon Timestream documentation](https://docs.aws.amazon.com/timestream/?icmpid=docs_homepage_databases).

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)