> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-architect.ipoint-labs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a real time data streaming system with Amazon Kinesis Data Stream and Kinesis Agent

> Hands-on lab · 30m

Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console.

<a className="ip-lab-portal-btn" href="https://labs.intellectualpoint.com/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab Details

1. This lab guides you through the process of deploying a sample website on an EC2 Linux instance, utilizing the Apache web server, and capturing real-time website logs. These logs are then streamed to AWS S3 for storage and analysis using a combination of Kinesis Data Streams, Kinesis Agent, Kinesis Firehose, and S3.
2. By following this lab, you will have the opportunity to practice working with these AWS services and create a comprehensive data pipeline for processing website logs.
3. Duration : **1 hour 30 minutes**
4. AWS Region : **US East (N. Virginia) us-east-1**

### Introduction

#### Amazon Kinesis Data Streams

* Data streaming technology enables a customer to ingest, process and analyze high volumes of data from a variety of sources.
* Kinesis data streams is one such scalable and durable real-time data streaming service.
* A Kinesis data stream is an ordered sequence of data records meant to be written to and read from in real time.
* The pricing of the data streams is on a per-shard basis.

#### Components

* Data record - The unit of data stored by Kinesis Data Stream.
* Data stream - represents a group of data records. The data records in a data stream are distributed into shards.
* Retention period - Length of time Data records are accessible from streams. A Kinesis data stream stores records from 24 hours by default, up to 365 days.
* Kinesis Client Library - Ensures that for every shard there is a record processor running and processing the shard.
* A **producer** puts data records into shards..
* A **consumer** gets data records from shards
* **Shard** - It has a sequence of data records in a stream.

  * There can be more than one shards. The number of shards required is mentioned while creating the data stream.
  * Total capacity of stream is the sum of capacities of its shards.
  * Ingest rate per shard - 1 MB or 1,000 messages per second.
  * Data read rate per shard - 2 MB per second.
  * Partition Key - Used to group data by shard within a stream.
* The stream records can be directly sent to services like S3, Redshift, ElasticSearch, etc. instead of creating consumer applications.

#### Amazon Kinesis Agent

* Amazon Kinesis agent is a Java software application that offers an easy way to collect and send data to Kinesis Data Firehose.
* The agent continuously monitors a set of files and sends new data to your Kinesis Data Firehose delivery stream.

### Architecture Diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/001.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=fa6d9dd51fe62458b0127f4aff9a2a8b" alt="" width="1999" height="553" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/001.png" />

### Case Study

1. Suppose an application is running on the EC2 Instance and it is generating continuous logs.
2. Those logs will be pushed into the Kinesis Data Streams.
3. From the Kinesis Data Streams, it gets consumed through the Kinesis Firehose.
4. The data from Kinesis Firehose is then saved into the S3 Bucket.

### Task Details

1. Sign in to AWS Management Console
2. Launching an EC2 Instance
3. SSH into EC2 Instance
4. Host a sample website
5. Set file permissions to httpd
6. Creating Kinesis data stream
7. Creating a S3 Bucket
8. Creating Kinesis Data Firehose
9. Creating and configuring Kinesis Agent
10. Testing the real-time streaming of data
11. Checking the CloudWatch metrics of Kinesis Data Streams and Data Firehose
12. Deleting AWS Resources

### Launching Lab Environment

1. To launch the lab environment, Click on the **Start Lab** button.
2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
3. Once the Lab is started, you will be provided with **IAM user name**, **Password**, **Access** **Key**, and **Secret** **Access** **Key**.

> **Note** : You can only start one lab at any given time

## Lab guide

### Lab Steps

#### Task 1: Sign in to AWS Management Console

1. Click on the **Open Console** button, and you will get redirected to AWS Console in a new browser tab and it will be Logged in Successfully.
2. On the AWS Console, in the search bar search for **IAM** and click on it.
3. Then Click on **IAM Users** and select **TerraformUser-XXXXX**

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/u9ozJNi80wMhhqMj/images/labs/access-s3-from-private-ec2-instance-using-vpc-endpoint/002.png?fit=max&auto=format&n=u9ozJNi80wMhhqMj&q=85&s=0f08b499adbb8238a6c3002c1d5280cc" alt="" width="1472" height="774" data-path="images/labs/access-s3-from-private-ec2-instance-using-vpc-endpoint/002.png" />
4. Click on **Create Access Key**.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/u9ozJNi80wMhhqMj/images/labs/access-s3-from-private-ec2-instance-using-vpc-endpoint/003.png?fit=max&auto=format&n=u9ozJNi80wMhhqMj&q=85&s=eb7aabd9a6c1d61ddacca5d1ed00bf2b" alt="" width="2892" height="718" data-path="images/labs/access-s3-from-private-ec2-instance-using-vpc-endpoint/003.png" />
5. Choose **Other**, Click on **Next** and click on **Create Access Key.**

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/u9ozJNi80wMhhqMj/images/labs/access-s3-from-private-ec2-instance-using-vpc-endpoint/004.png?fit=max&auto=format&n=u9ozJNi80wMhhqMj&q=85&s=d6dff4ae8d358ff810d879e8653edf67" alt="" width="2390" height="1378" data-path="images/labs/access-s3-from-private-ec2-instance-using-vpc-endpoint/004.png" />
6. Your **Access and Secret key** will get Created. Make a note of it for later use.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/u9ozJNi80wMhhqMj/images/labs/access-s3-from-private-ec2-instance-using-vpc-endpoint/005.png?fit=max&auto=format&n=u9ozJNi80wMhhqMj&q=85&s=31dcaac5e27990f7cb20ef4a1abf2eb4" alt="" width="1858" height="1004" data-path="images/labs/access-s3-from-private-ec2-instance-using-vpc-endpoint/005.png" />

#### Task 2: Launching an EC2 Instance

1. Make sure you are in **US East (N. Virginia) us-east-1** Region.
2. Navigate to **EC2** by clicking on the **Services** menu at the top, then click on **EC2** in the **Compute** section.
3. Navigate to **Instances** on the left panel and click on **Launch Instance** button.
4. Enter **Name** as **Demo\_Instance**
5. Select **Amazon Linux** from the **Quick Start.**

* **Choose an Amazon Machine Image (AMI):** Choose **Amazon Linux 2023 AMI** from the drop-down.

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/002.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=0b014f1d0738f40abec8ea7ef7c4892a" alt="" width="1215" height="652" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/002.png" />

6. Choose an Instance Type: Select **t2.micro**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/003.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=d4e95870b1726f7c09035f076ac07cde" alt="" width="978" height="256" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/003.png" />

7. For Key pair : Choose **Create a new key pair**

* Key Pair name :  Enter  **WhizKey**
* Key pair type **:** Choose **RSA**
* Private key file format: Choose **.pem**
* Click on **Create key pair** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/004.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=8e0bc8506d97b8e1719f5cc9c26a9d8e" alt="" width="748" height="771" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/004.png" />

8. In Network Settings Click on **Edit** Button:

   * Auto-assign public IP: Select **Enable**
   * Select **Create new Security group**
   * Security group name : Enter **kinesis\_demo\_SG**
   * Description : Enter **Security Group to allow traffic to EC2**
   * SSH rule will already be present for you. To add HTTP:

     * Select **Add Security rule** Button
     * Choose Type: **HTTP**
     * Source:  Select **Anywhere**
9. Under **Advanced Details,**

   * IAM Instance profile : Select **EC2\_Role\_\<RANDOM\_NUMBER>**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/005.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=9b62aa304786e7524ad9f0455904d056" alt="" width="962" height="239" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/005.png" />

10. Keep Rest thing Default and Click on **Launch Instance** Button.
11. Select **View all Instances** to View Instance you Created
12. **Launch Status:** Your instances are now launching, Navigate to **Instances** page from left menu and wait the status of the EC2 Instance changes to running and health check status changes to **2/2 checks passed**
13. Select the Instance and copy the Public IPv4 address from the Details section. Note down the Public IPv4 Address of your EC2 instance. A sample is shown in the screenshot below.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/006.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=ff9209d87a29f7cedd86f9eaa22a4225" alt="" width="976" height="334" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/006.png" />

#### Task 3: SSH into EC2 Instance

1. Please follow the steps in [SSH into EC2 Instance](https://play.whizlabs.com/site/task_support/ssh-into-ec-instance).

#### Task 4: Host a sample website

In this task, we will host a sample website by navigating to the HTML folder present in the var directory and then we will fetch the sample site using the wget command.

1. Switch to the root user :

   ```
   sudo -s
   ```
2. Run all the updates using the yum command:

   ```
   dnf update -y
   ```
3. Install the LAMP and HTTPD server:

   ```
   sudo dnf install -y httpd mariadb105 php php-mysqlnd
   ```
4. Start the HTTPD server:

   ```
   sudo systemctl start httpd
   ```
5. Enable the HTTPD server:

   ```
   sudo systemctl enable httpd
   ```
6. Navigate to the HTML folder path.

   ```
   cd /var/www/html
   ```
7. Download the zip file attached [here](https://labresources.whizlabs.com/70f3c25a20bcbaa8bc3098c1bb644132/marvel-master.zip) and make sure it is located in your downloads. This is the working Marvel template source.
8. Open a new terminal. Then Run the following command to upload the zip file into the EC2.

   ```
   scp -i ~/Downloads/WhizKey.pem ~/Downloads/marvel-master.zip ec2-user@YOUR_PUBLIC_IP:/tmp/
   ```

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/007.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=3e491da6c07a0d05e7b7df5b9d69f686" alt="" width="1469" height="200" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/007.png" />
9. Navigate back to your EC2 terminal. Run the following code. Then you should see the uploaded zip.

   ```plaintext theme={null}
   ls -lh /tmp/marvel-master.zip
   ```

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/008.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=6492e52a17287b2766daccd439ab6ca6" alt="" width="1050" height="58" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/008.png" />
10. Then run the following code.

```plaintext theme={null}
mv /tmp/marvel-master.zip /var/www/html/
```

```plaintext theme={null}
cd /var/www/html
ls -lh
```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/009.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=662be08ca53dfe11d2aff9de2f653d96" alt="" width="954" height="167" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/009.png" />

11. Unzip the downloaded html template. Use the zip file name to unzip.

```
sudo unzip marvel-master.zip
```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/010.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=a700c36320a6ece02e0e79915bccc35a" alt="" width="905" height="757" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/010.png" />

12. Use the command **ls** to list all the files and folders present in the present working directory.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/011.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=d7a3f2ad6f453ba7a9081071e35cbb8a" alt="" width="798" height="122" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/011.png" />

13. You will be able to see a **zip file** and a **folder**. When we unzipped the marvel.zip, we got the folder, **marvel-master**.

14. Copy the folder name to a text editor.

15. To verify if the sample website is hosted, paste **[http://IP\\\_Address/folder\\\_name](http://IP\\_Address/folder\\_name)** in the browser and press **\[Enter]**

* For example - http\://**34.233.120.188**/**marvel-master**/

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/012.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=d86a417a0544d6f150f07b01294447ea" alt="" width="1222" height="754" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/012.png" />

16. You can see that the website is hosted successfully.

17. The website logs will be in the path “**/var/log/httpd/access\_log**”. For each click and use of the website, the related logs will be collected and stored here.

18. You can check the logs using the following commands

```
sudo su
```

```
cd /var/log/httpd/
```

```
tail -10 access_log
```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/013.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=19663ad238516c742bd9c53867d32bbb" alt="" width="1467" height="619" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/013.png" />

#### Task 5: Set file permissions to httpd

Now let's see how to store these continuous logs. Before proceeding, change the permission of the httpd folder, so that the file will be in readable, writable, and executable mode by ec2-user.

1. Add the **httpd** group to your EC2 instance with the command

   ```
   groupadd httpd
   ```
2. Add **ec2-user** user to the **httpd** group with the command

   ```
   usermod -a -G httpd ec2-user
   ```
3. To refresh your permissions and include the new httpd group, log out completely with the command

   ```
   exit
   ```

   * **exit** (if you are in the sudo, you have to exit twice)
4. Follow the steps to [SSH into EC2 Instance](https://play.whizlabs.com/site/task_support/ssh-into-ec-instance). If possible do in the new terminal.
5. Verify that the **httpd** group exists with the groups with the command

   ```
   groups
   ```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/014.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=740adb0d9dec18fd56582cb8cc1f362c" alt="" width="956" height="411" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/014.png" />

6. Change the group ownership of the **/var/log/httpd** directory and its contents to the **httpd** group,

   ```
   sudo chown -R root:httpd /var/log/httpd
   ```
7. Change the directory permissions of /var/log/httpd and its subdirectories to add group write permissions and set the group ID on subdirectories created in the future,

```
sudo chmod 2775 /var/log/httpd
```

```
find /var/log/httpd -type d -exec sudo chmod 2775 {} +
```

#### Task 6: Creating Kinesis Data Stream

Let us create a Kinesis data stream. The logs created in the EC2 sample website will be pushed to Kinesis data stream.

1. Make sure you are in the **US East (N. Virginia) us-east-1** Region.

2. Navigate to **Kinesis** by clicking on the **Services** menu, under the **Analytics** section.

3. Under **Get Started**, select **Kinesis Data Streams** and click on **Create data stream**.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/015.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=2bdf78355aa6e2dcc91a04b103ba6003" alt="" width="1966" height="850" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/015.png" />

4. Under **Data stream name**, enter the **Data stream name** as **whiz-data-stream.**

5. Leave everything as default. Click on **Create data stream** button.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/016.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=2471cc3cfbb6b4a7aaf1761a01cde282" alt="" width="2210" height="774" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/016.png" />

6. Once the status is active, Click on the **Configuration** tab.

7. Scroll down to **Encryption** and click on **Edit** button.

8. Check **Enable server-side encryption** and use the default encryption key type, i.e **Use AWS managed CMK**.

9. Click on **Save changes** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/017.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=99b5f1b881b94cb0a26f6df9a3802728" alt="" width="1444" height="336" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/017.png" />

10. You have used AWS KMS to encrypt your data.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/018.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=965db684c9dde8d53b9529774e54c899" alt="" width="519" height="195" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/018.png" />

#### Task 7: Creating a S3 Bucket

In this task, we will create an S3 bucket where we will store the data from the firehose.

1. Navigate to **S3** by clicking on the **Services** menu, under the **Storage** section.
2. Click on **Create bucket** button.
3. In the General Configuration,

   * **Bucket name**: Enter **whiz-demo-logs**

     > **Note:** S3 Bucket names are globally unique, choose a name that is available.
4. **Region**: Select **US East (N. Virginia) us-east-1** (i.e same region as the Kinesis data stream).
5. In the Default encryption,

* **Encryption key type**: Leave the key type as **Amazon S3 key (SSE-S3)**.
* **Bucket key**: Select **Enable**

6. Click on **Create bucket** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/019.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=aa1863689f5bf48fc8a2c95fccb088a7" alt="" width="965" height="284" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/019.png" />

#### Task 8: Creating Amazon Data Firehose - Kinesis Data Firehose

Once the streaming service gets the data from the logs, then we need to push the data somewhere. It is not possible to post the data from the Kinesis Data Streams. So we will use Kinesis Data Firehose.

1. Make sure you are in the **US East (N. Virginia) us-east-1** Region.
2. Navigate to **Kinesis** by clicking on the **Services** menu, under the **Analytics** section.
3. Under **Get Started**, select **Amazon Data Firehose** and click on **Create Firehose stream**.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/020.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=5a00fe87306fca31d27fa891d7d9ec30" alt="" width="1106" height="444" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/020.png" />
4. Under **Choose Source and Destination**,

   * **Source**: Choose **Amazon Kinesis Data Streams.**
   * **Destination**: Choose **Amazon S3**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/021.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=0cd75eeceed74e02d7f1ba2b102ddfde" alt="" width="1002" height="342" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/021.png" />

5. Under **Firehose stream name**, Enter **stream name** as **whiz-data-stream.**

6. Under the **Source settings**,

* Click on **Browse** button.
* From the pop-up, select the Data Stream we have created earlier.

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/022.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=2b116698530dfcd2630e5dcfe4ba5e6d" alt="" width="1335" height="299" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/022.png" />
* Click on **Choose** button.

7. Leave the **Transform and convert records** as default.

8. Under the **Destination settings**,

* Click on **Browse** button.
* From the pop-up, select the S3 Bucket we have created earlier, in my case, **whiz-demo-logs**

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/023.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=9d5907b1bddb8e60dde0bb3f6f42bcd0" alt="" width="1335" height="298" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/023.png" />
* Click on **Choose** button.

9. Expand the **Buffer hints, compression and encryption** section. Under the **Buffer interval**, make it to **60 seconds**.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/024.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=825f9846fd12dc7de098ae298542f523" alt="" width="490" height="347" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/024.png" />

10. Expand the **Advanced settings**,

* Under **Service access**, **Choose existing IAM role** and select it from the dropdown menu.

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/025.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=bff653c36ae52182ec47b2b1b90ad86b" alt="" width="1402" height="353" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/025.png" />

11. Click on **Create Firehose stream** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/026.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=25d9070a65fc14f970b267377f640cfd" alt="" width="1476" height="430" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/026.png" />

#### Task 9: Creating and configuring Kinesis Agent

Let us configure a Kinesis agent which will collect data and send it to Kinesis Data Streams.

1. Follow the steps again to [SSH into the EC2 instance](https://www.whizlabs.com/labs/support-document/ssh-into-ec-instance/).
2. Let us install the latest version of Kinesis agent on the instance.

   ```
   sudo dnf install -y https://s3.amazonaws.com/streaming-data-agent/aws-kinesis-agent-latest.amzn2.noarch.rpm
   ```

   * Type “**y**” if asked in the installation process.
3. After installing the Kinesis agent, let us update the json file available in the path **/etc/aws-kinesis/agent.json**.
4. Edit the **agent.json**,

   ```
   sudo nano /etc/aws-kinesis/agent.json
   ```

   * **Remove** all the content and paste the below JSON content.
   * **Note 1**: Make sure you copy the “**awsAccessKeyId**” , "**awsSecretAccessKey**" from the lab page and paste it the JSON code wherever required.
   * **Note 2**: Make sure the “filePattern” consists of the log file path which is default in this case and “**kinesisStream**” consists of the created Kinesis Data Stream name.
   * Press “**ctrl** + **x**” to save. Press “**y**” to save the modified changes and press **Enter** (Follow the commands to save the file carefully).

```plaintext theme={null}
{
  "cloudwatch.emitMetrics": true,
  "kinesis.endpoint": "",
  "firehose.endpoint": "",
  "awsAccessKeyId": "A*****************",
  "awsSecretAccessKey": "B******************",
  "flows": [
    {
      "filePattern": "/var/log/httpd/access_log",
      "kinesisStream": "whiz-data-stream",
      "partitionKeyOption": "RANDOM"
    }
  ]
}
```

5. Make sure you specify the “**awsAccessKeyId**” "**awsSecretAccessKey**" from the lab page.

6. The name of the kinesis stream ( “**kinesisStream**” ) to which the agent sends data. Change the kinesisStream name according to the name you created.

7. Whenever you change the configuration file (**agent.json**), you must stop and start the agent, using the commands.

   ```
   sudo service aws-kinesis-agent stop
   ```

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/027.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=44191f732478d77c1465e4b3d78bf89b" alt="" width="769" height="135" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/027.png" />

   ```
   sudo service aws-kinesis-agent start
   ```

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/028.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=a43966cf0d4833415f0eb07f130ff279" alt="" width="747" height="78" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/028.png" />

8. Once the agent is started for the first time, a log file will be created. Check the log file using the commands,

   ```
   cd /var/log/aws-kinesis-agent/
   ```

   ```
   ls -ltr
   ```

9. You can check if the service is started properly by going through the log.

```
tail aws-kinesis-agent.log | grep "completed"
```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/029.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=b071a980aacd542110752d407acddb31" alt="" width="1430" height="193" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/029.png" />

10. We can see that the agent is successfully started.

#### Task 10: Testing the real-time streaming of data

Let us test by hosting the above sample website on multiple browsers or do some click activity on the website. The related logs will be collected on the listed S3 bucket.

1. To test the data streaming, paste your **IP\_Address/folder\_name** in the multiple browsers and press enter.

   * For example - **[http://34.233.120.188/marvel-master/](http://34.233.120.188/marvel-master/)**

     > **Note:** The folder\_name is the unzipped folder of the sample website which we have noted earlier in the Task 5.
2. Once you have followed the above step, click on the website links present to create more logs.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/030.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=cffeb7daf4adf123d4e7b363d4a3ca55" alt="" width="1244" height="614" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/030.png" />

> **Note:** We are clicking the links in the sample website website to generate logs which will be streamed to the created S3 Bucket.

3. Navigate to **S3** by clicking on the **Services** menu, under the **Storage** section.

   > **Note:** Wait for 3-5 minutes, if you are not able to see the logs.

4. You will see a hierarchy of folders with **year** > **month** > **date** > **hour**.

5. Click on the date or hour to see the logs created.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/031.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=90fc5a117e5589d65960ed887ca33545" alt="" width="1406" height="766" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/031.png" />

6. Click on the log and select **Open** and save the file.

7. Open the log file in any text editor in the local and check the logs.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/032.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=5beb9fc1ab1d32843bd043bdecf44d2e" alt="" width="691" height="423" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/032.png" />

> **Note:** The more the clicks in the page, the more the logs are generated. In this demo webpage, we have only 1 page. So try to open the webpage in many browsers and click on the links to generate the logs.

#### Task 11: Checking the CloudWatch metrics of Kinesis Data Stream and Firehose

Let us the check the CloudWatch metrics of Kinesis Data Stream which records the data and Kinesis Delivery stream which reads the data from Data Stream.

1. Make sure you are in the **US East (N. Virginia) us-east-1** Region.
2. Navigate to **Kinesis** by clicking on the **Services** menu, under the **Analytics** section.
3. Click on the created data stream in **Data Streams** section and navigate to the **Monitoring** tab. You will be able to see the graph according to the logs generated.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/033.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=3cd16f2c87358eca2d66abc0c6972cc5" alt="" width="1434" height="786" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/033.png" />

4. On the left navigation panel, click on the **Amazon Data Firehose**.
5. Click on the created delivery stream and navigate to the **Monitoring** tab. You will be able to see the graph.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/034.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=ce866450bb853f88277c8d2575e2ac3e" alt="" width="967" height="619" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/034.png" />

> ##### Do you know ?
>
> Amazon Kinesis Data Streams supports the concept of shards, which are the fundamental units of data capacity within a stream. Each shard in a Kinesis Data Stream can handle up to 1 MB/sec of data input and 2 MB/sec of data output. However, with the use of Kinesis Data Firehose, you can easily ingest data into Kinesis Data Streams at a much higher rate, exceeding the individual shard limits.

1. Once the lab steps are completed, please click on the **Validation** button on the right side panel.
2. In the second checkbox in the validation part, you should mention the folder name alone i.e., **marvel-master.**

#### Task 12: Delete AWS Resources

##### Terminating EC2 Instance :

1. Make sure you are in the **US East** (**N.Virginia) us-east-1** Region.
2. Navigate to the **Services** menu at the top left corner and click on **EC2** present under the **Compute** section.
3. Click on **Instances** from the left navigation menu.
4. Select the created instance and click on **Instance state**.
5. From the drop-down menu select **Terminate instance**.
6. Confirm the terminate by clicking on **Terminate** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/036.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=98c0158c76711d0ae2c21e4d7272174d" alt="" width="754" height="409" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/036.png" />

##### Deleting Kinesis Data Streams :

1. Make sure you are in the **US East** (**N.Virginia) us-east-1** Region.
2. Navigate to **Kinesis** by clicking on the **Services** menu, under the **Analytics** section.
3. On the left panel, click on the **Data streams**.
4. Select the created data stream and click on the **Actions** button.
5. Select **Delete** from the drop-down.
6. Confirm by typing **Delete** and click on **Delete** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/037.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=2474dab61c18c0e84c17259736a18513" alt="" width="759" height="386" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/037.png" />

##### Deleting Kinesis Delivery Streams :

1. Make sure you are in the **US East** (**N.Virginia) us-east-1** Region.
2. Navigate to **Kinesis** by clicking on the **Services** menu, under the **Analytics** section.
3. On the left panel, click on the **Data Firehose**.
4. Select the created delivery stream.
5. Select **Delete**.
6. Confirm by typing the delivery stream name in the field and click on **Delete** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/1rdENrngau2mVfJg/images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/038.png?fit=max&auto=format&n=1rdENrngau2mVfJg&q=85&s=4c2990863b7bef6d021cdd900bb01bd7" alt="" width="681" height="291" data-path="images/labs/build-a-real-time-data-streaming-system-with-amazon-kinesis-data-stream-and-kine/038.png" />

### Completion and Conclusion

1. You have successfully launched an EC2 Instance.
2. You have successfully hosted a sample website.
3. You have successfully set file permissions to httpd.
4. You have successfully created Kinesis data stream.
5. You have successfully created a S3 Bucket.
6. You have successfully created Kinesis Data Firehose.
7. You have successfully created and configured Kinesis Agent.
8. You have successfully tested the real-time streaming of data.
9. You have successfully checked the CloudWatch metrics of Kinesis Data Streams and Data Firehose.

### End Lab

1. Sign out of the AWS Account.
2. You have successfully completed the lab.
3. Once you have completed the steps, click on **End Lab** from your IP Lab Portal and wait till the process gets completed.

## What gets checked

When you press **Check my work**, the platform verifies each of these:

* **Launch an EC2 Instance** — Check whether an EC2 Instance is launched or not.
* **Check EC2 Instance Running State** — Check whether the EC2 instance is in a running state.
* **Launch EC2 AMI type Amazon Linux** — Check whether the EC2 instance is launched using an Amazon AMI.
* **Validate EC2 Instance Type t2.micro** — Check whether the EC2 instance type is t2.micro.
* **Create an Amazon Kinesis Data Firehouse Delivery stream** — Check whether an Amazon Kinesis Firehouse Delivery Stream is created
* **Create an Amazon Kinesis Data stream** — Check whether an Amazon Kinesis Data Stream is created with encryption as enabled or not
* **check s3 object** — Check whether an object is uploaded to the S3 bucket.
* **Create Private S3 bucket** — Check whether a private S3 bucket is created or not

## Related help

* [FAQs and Troubleshooting](/aws-saa/support/faqs-and-troubleshooting)
* [SSH into EC2 Instance](/aws-saa/support/ssh-into-ec2-instance)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.