Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Mar 27, 2024
Difficulty: Easy

Amazon Kinesis Data Analytics

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

Introduction

Using Amazon Kinesis Data Analytics for SQL Applications, you may use conventional SQL to process and analyze streaming data. The service allows you to quickly develop and run robust SQL code against streaming sources to do time-series analytics, feed real-time dashboards, and generate real-time metrics.

Amazon Kinesis Data Firehose (Amazon S3, Amazon Redshift, Amazon OpenSearch Service, and Splunk), AWS Lambda, and Amazon Kinesis Data Streams are supported as destinations by Kinesis Data Analytics.

Use of Amazon Kinesis Data Analytics

Amazon Kinesis Data Analytics enables you to rapidly write SQL code that reads, analyses, and saves data in real-time. You may build apps that convert and deliver insights into your data using standard SQL queries on streaming data. The following are some use-case examples for Kinesis Data Analytics:

  • Generate time-series analytics: Metrics may be calculated over time frames and then sent to Amazon S3 or Amazon Redshift using a Kinesis data delivery stream.
  • Feed real-time dashboards: You may feed real-time dashboards with aggregated and processed streaming data results.
  • Create real-time metrics: Custom metrics and triggers may be created for usage in real-time monitoring, alerts, and alarms.
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

How Amazon Kinesis Data Analytics Works

Kinesis Data Analytics programs continually read and process real-time streaming data. You build SQL application code to process incoming streaming data and generate output. The output is then written to a location specified by Kinesis Data Analytics. The figure below depicts a typical application architecture.

 

Source: https://docs.aws.amazon.com/kinesisanalytics/latest/dev/images/kinesis-app.png

 

Each app has a name, a description, a version ID, and a status. When you initially construct an application, Amazon Kinesis Data Analytics provides it with a version ID. When we edit any program settings, this version ID is updated. Kinesis Data Analytics changes the current application version ID when you add an input configuration, add or remove a reference data source, add or delete an output configuration, or alter application code. Kinesis Data Analytics also keeps track of when an application was developed and when it was last updated.

 

In addition to these fundamental qualities, each application includes the following:

  • Input: Your application's streaming source. You may choose between a Kinesis data stream and a Kinesis Data Firehose data delivery stream as the streaming source. The streaming source is mapped to an in-application input stream in the input settings. The in-application stream functions similarly to a continually updating table on which you can execute SQL operations such as SELECT and INSERT. Additional in-application streams can be created in your application code to store intermediate query results.
  • Application Code: A set of SQL statements that process input and output results. SQL statements can be written against in-application streams and reference tables. JOIN queries can also integrate data from both of these sources.
  • Output: Query results are sent to in-application streams in the application code. To keep intermediate results, you can build one or more in-application streams in your application code. You may then set the application output to persist data to external destinations in the in-application streams that retain your application output (also known as in-application output streams). A Kinesis Data Firehose delivery stream or a Kinesis data stream can be used as an external target.
     

Take notice of the following as well:

  • To read data from a streaming source and publish application output to external destinations. These rights are granted via IAM roles.
  • For each application, Kinesis Data Analytics automatically generates an in-application error stream. If your application encounters problems while processing specific entries (for example, a type mismatch or a late arrival), the record is posted to the error stream. You may tell Kinesis Data Analytics to persist error stream data to an external location for additional analysis by configuring application output.
  • Amazon Kinesis Data Analytics guarantees that the output records of your application are sent to the specified destination. Even if the programme is interrupted, it employs an "at least once" processing and delivery methodology.
    Must read, Amazon Hirepro

Getting Started with Amazon Kinesis Data Analytics

This section demonstrates how to use Amazon Kinesis Data Analytics for SQL Applications.

Step 1: Set Up an Account and Create an Administrator User

Complete the following tasks before using Amazon Kinesis Data Analytics for the first time:

  1. Sign Up for AWS
  2. Create an IAM User

 

Sign Up for AWS

When you join Amazon Web Services, your account is immediately registered for all AWS services, including Amazon Kinesis Data Analytics. You are only charged for the services you utilise. You only pay for the resources you utilise using Kinesis Data Analytics. You can get started with Kinesis Data Analytics for free if you are a new AWS client.

 

Create an IAM User

When you use AWS services, such as Amazon Kinesis Data Analytics, you must submit credentials so that the service can assess if you have the authorisation to access the resources held by that service. The console requires your password. To use the AWS CLI or API(Application programming interface), you can create access keys for your AWS account. However, we do not suggest that you access AWS using your AWS account credentials. We propose that you utilise AWS Identity and Access Management instead (IAM). Create an IAM user, add the user to an IAM group with administrative access, and then grant the IAM user administrative permissions. You may then access AWS using a unique URL and the credentials of that IAM user.

If you've signed up for AWS but haven't yet established an IAM user, you may do so using the IAM interface.

The Getting Started activities in this tutorial require that you have an administrative user (adminuser). To create an adminuser in your account, follow the steps below.

To sign in to the terminal and establish an administrator user

  1. In your AWS account, create an administrator user named adminuser.
  2. A user can access the AWS Management Console by entering a unique URL.

Step 2: Set Up the AWS Command Line Interface (AWS CLI)

Follow the steps below to do this step

  1. Download and configure the AWS CLI.
  2. In the AWS CLI configuration file, create a named profile for the administrator user. This profile is used for running AWS CLI commands.

 

[profile adminuser]

aws_access_key_id = adminuser access key ID

aws_secret_access_key = adminuser secret access key

region = aws-region

 

3. Verify the configuration by typing the help command at the command prompt:

Step 3: Create Your Starter Amazon Kinesis Data Analytics Application

You may use the console to construct your first Kinesis Data Analytics application by following the procedures in this section.

Step 3.1: Create an Application

For this, we have to follow the steps given below:

  1. Log in to the AWS Management Console and launch the Kinesis Data Analytics service.
  2. Select Create application.
  3. Type an application name, a description, and SQL for the application's Runtime option, and then click Create an application on the Create application page.

 

Source: https://docs.aws.amazon.com/kinesisanalytics/latest/dev/images/gs-v2-10.png

 

Step 3.2: Configure Input

A streaming source is required for your application. The console may generate a demo stream to assist you in getting started (called kinesis-analytics-demo-stream). The terminal also executes a script that populates the stream with records.

Follow the steps below to add a streaming source to your application:

  1. Select Connect streaming data from the application hub page in the console.

 

Source: https://docs.aws.amazon.com/kinesisanalytics/latest/dev/images/gs-v2-20.png

 

 2. Examine the following items on the subsequent page:

  • Source section
  • Stream reference name(SOURCE_SQL_STREAM_001)
  • Record pre-processing with AWS Lambda

 3. On the Source page, choose to Configure a new stream.

 4. Select Create a demo stream. The console configures the application input as follows:

  • The console generates the kinesis-analytics-demo-stream data stream.
  • The console feeds sample stock ticker data into the stream.
  • The console infers a schema by reading sample records from the stream using the DiscoverInputSchema input action. The inferred schema is the schema for the produced in-application input stream.
    The console displays the inferred schema and the sample data used to infer the schema from the streaming source.

Source: https://docs.aws.amazon.com/kinesisanalytics/latest/dev/images/gs-v2-30.png

 

The following items may be found on the Stream sample console page:

  • The Raw stream sample tab displays the raw stream records collected to infer the schema by the DiscoverInputSchema API operation.
  • The tabular form of the data in the Raw stream sample tab is shown in the Formatted stream sample tab.
  • If you select Edit schema, you may change the inferred schema. Don't modify the inferred schema for this exercise. See Working with the Schema Editor for additional information on modifying a schema.
    If you select Rediscover schema, the console will run DiscoverInputSchema again and infer the schema.

 5. Select Save and Continue.

Step 3.3: Add Real-Time Analytics (Add Application Code)

You can build your SQL queries against the in-app stream, but you should utilise one of the templates that include example code for the next phase.

  1. Select Go to SQL editor from the application hub page.

Source: https://docs.aws.amazon.com/kinesisanalytics/latest/dev/images/gs-v2-40.png

 

2. Choose Yes, start the program in the Would you like to start running "ExampleApp"? dialogue box.

    The console sends an application start request (see StartApplication), and the SQL editor screen opens.

3 The console displays the SQL editor page. Examine the page, particularly the buttons (Add SQL from templates, Save and execute SQL) and tabs.

4. Select Add SQL from templates in the SQL editor.

5. Select Continuous filter from the list of possible templates. The following code gets data from one in-application stream (the WHERE clause selects the rows) and puts it into another:

  • It builds the DESTINATION_SQL_STREAM in-app stream.
  • It builds a STREAM_PUMP and employs it to pick rows from SOURCE_SQL_STREAM_001 and insert them into DESTINATION_SQL_STREAM.

6. Select Add this SQL to the editor.

7. Test the application code as follows:

Remember that you have already launched the application (status is RUNNING). As a result, Amazon Kinesis Data Analytics is already reading from the streaming source and appending rows to the in-app stream SOURCE_SQL_STREAM_001.

  1. Select Save and execute SQL in the SQL Editor. To store the application code, the console first makes an update request. The code then runs indefinitely.
  2. The results are available in the Real-time analytics tab.

Source: https://docs.aws.amazon.com/kinesisanalytics/latest/dev/images/gs-v2-50.png

Streaming SQL Concepts

Amazon Kinesis Data Analytics uses enhancements to the ANSI 2008 SQL standard. These extensions allow you to work with streaming data. The following sections discuss essential streaming SQL principles.

In-Application Streams and Pumps

You map a streaming source to a newly formed in-application stream when you set up application input. Data flows continually from the streaming source into the in-app stream. An in-application stream functions similarly to a table that can be queried using SQL commands, but it is referred to as a stream since it depicts continuous data flow.

Timestamps and the ROWTIME Column

ROWTIME is a specific column seen in in-application streams. Amazon Kinesis Data Analytics saves a timestamp when it adds a record in the first in-application stream. The timestamp at which Amazon Kinesis Data Analytics placed a record into the first in-application stream after reading from the streaming source is reflected in ROWTIME. This ROWTIME value is then kept across your application.

Continuous Queries

A query over a stream runs indefinitely, overflowing data. This continuous execution enables situations such as the ability for apps to query a stream and create warnings in real-time.

Windowed Queries

SQL queries in your application code run indefinitely across in-app streams. An in-application stream is a continuous flow of unlimited data through your application. As a result, to obtain result sets from this constantly changing input, queries are frequently constrained using a window defined in terms of time or rows. These are also known as windowed SQL.

Kinesis Data Analytics supports the following window types:

  • Stagger Windows: An aggregate query that uses keyed time-based windows that open as data comes. Multiple overlapping windows are possible thanks to the keys. Because Stagger Windows minimize late or out-of-order data more than Tumbling Windows, this is the preferred approach to aggregate data using time-based windows.
  • Tumbling Windows: A query aggregates data by opening and closing various time-based windows at regular intervals.
  • Sliding Windows: A query that constantly aggregates data using a fixed time or row count interval.

Streaming Data Operations: Stream Joins

In your application, you can have many in-application streams. To correlate data coming on these streams, you can use JOIN queries. Assume that you have the following in-application streams:

  • OrderStream: Receives stock orders as they are entered.

 

(orderId SqlType, ticker SqlType, amount SqlType, ROWTIME TimeStamp)

 

  • TradeStream: Receives resulting stock trades for those orders.

 

(tradeId SqlType, orderId SqlType, ticker SqlType, amount SqlType, ticker SqlType, amount SqlType, ROWTIME TimeStamp)

Security in Amazon Kinesis Data Analytics

AWS prioritizes cloud security above anything else. As an AWS client, you will have access to a data center and network architecture designed to fulfill the needs of the most security-conscious enterprises.

AWS and you share responsibility for security. The shared responsibility paradigm defines this as cloud security and cloud security:

Security of the Cloud: AWS is in charge of securing the infrastructure that powers AWS services on the AWS Cloud. AWS also offers services that may be used securely. As part of the AWS compliance processes, third-party auditors regularly examine and verify our security's efficacy.

Security in the Cloud: The AWS service you use determines your obligation. You are also responsible for additional aspects such as the sensitivity of your data, the requirements of your company, and relevant laws and regulations.

Frequently Asked Questions

How does Kinesis data analytics work?

Amazon Kinesis Data Analytics enables you to rapidly write SQL code that reads, analyses, and saves data in real-time. You may build apps that convert and deliver insights into your data using normal SQL queries on streaming data.

Is it possible to query data using Kinesis data analytics?

Your Kinesis Data Analytics SQL application receives new data continually from streaming data sources as it comes in real-time. An in-application stream makes the data available to your SQL code. Because you can build, insert, and select from an in-application stream, it functions similarly to a SQL table.

Which of the following are examples of how Amazon Kinesis streams may be used for analytics?

The following are examples of common scenarios for using Kinesis Data Streams: Log and data feed intake is accelerated: Instead of waiting for the data to be batch-processed, you may have your data producers push data to a Kinesis data stream as soon as it is created, eliminating data loss in the event of a producer failure.

What kind of data does Amazon Kinesis handle?

You may use Amazon Kinesis to store real-time data such as video, audio, application logs, website clickstreams, and IoT telemetry for machine learning, analytics, and other applications.

What is the distinction between Kinesis data streams and Firehose data streams?

Kinesis Data Streams is primarily concerned with consuming and storing data streams. Kinesis Data Firehose is designed to provide data streams to specific destinations. Both can consume data streams, but which to utilise depends on where you want your streaming data to go.

Conclusion

In this article, we have extensively discussed Amazon Kinesis Data Analytics. We start with a brief introduction to Amazon Kinesis Data Analytics, then discuss the steps to use it.

After reading about the Amazon Kinesis Data Analytics, are you not feeling excited to read/explore more articles on the topic of AWS? Don't worry; Coding Ninjas has you covered. To learn, see AWS Cloud MapAWS Cloud DirectoryAWS Application Discovery Service, and Data Exchange in AWS.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! You can also consider our Data Analytics Course to give your career an edge over others.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Topics covered
1.
Introduction
2.
Use of Amazon Kinesis Data Analytics
3.
How Amazon Kinesis Data Analytics Works
4.
Getting Started with Amazon Kinesis Data Analytics
4.1.
Step 1: Set Up an Account and Create an Administrator User
4.2.
Step 2: Set Up the AWS Command Line Interface (AWS CLI)
4.3.
Step 3: Create Your Starter Amazon Kinesis Data Analytics Application
5.
Streaming SQL Concepts
5.1.
In-Application Streams and Pumps
5.2.
Timestamps and the ROWTIME Column
5.3.
Continuous Queries
5.4.
Windowed Queries
5.5.
Streaming Data Operations: Stream Joins
6.
Security in Amazon Kinesis Data Analytics
7.
Frequently Asked Questions
7.1.
How does Kinesis data analytics work?
7.2.
Is it possible to query data using Kinesis data analytics?
7.3.
Which of the following are examples of how Amazon Kinesis streams may be used for analytics?
7.4.
What kind of data does Amazon Kinesis handle?
7.5.
What is the distinction between Kinesis data streams and Firehose data streams?
8.
Conclusion