Amazon Kinesis Data Streams
Integrating AWS Kinesis Data Streams as a Source with GlassFlow
This tutorial will guide you through integrating AWS Kinesis Data Streams with GlassFlow. AWS Kinesis is a real-time data streaming service that allows you to collect and process large streams of data records in real-time. By integrating Kinesis Data Streams with GlassFlow, you can build powerful data pipelines for real-time analytics and processing.
Prerequisites
Before you start, make sure you have the following:
A GlassFlow account. Sign up for a free GlassFlow account.
You have an AWS account.
You installed AWS CLI.
Python is installed on your machine.
Pip is installed to manage project packages.
Scenario overview
This project simulates a scenario where Netflix viewing metrics data is monitored and processed in real-time to improve user experience and content delivery. Generated sample data streamed continuously into Amazon Kinesis Data Streams. The goal is to ingest metrics data into GlassFlow, analyze the user reactions based on the watch frequency, categorize the reactions into like, favorite, or dislike.
Step 1: AWS Configuration
We use Boto3 (AWS SDK for Python) to create a Kinesis stream and send sample data.
Create IAM user
Before using Boto3, you need to set up authentication credentials for your AWS account using either the IAM Console or the AWS CLI. You can either choose an existing root user or create a new one.
For instructions about how to create a user using the IAM Console, see Creating IAM users. Once the user has been created, see Managing access keys to learn how to create and retrieve the keys used to authenticate the user.
Copy both generated aws_access_key_id
and aws_secret_access_key
, you will use them when you configure the local credentials file and to set environment variables.
Configure credentials file
Use AWS CLI installed to configure your credentials file by running the below command:
Alternatively, you can create the credentials file yourself. By default, its location is ~/.aws/credentials
. in MacOS/Linux operating systems At a minimum, the credentials file should specify the access key and secret access key. In this example, the key and secret key for the account are specified in the default
profile:
You may also want to add a default region to the AWS configuration file, which is located by default at ~/.aws/config
:
Alternatively, you can pass an AWS_REGION
name as an environment variable when creating clients and resources.
You have now configured credentials for the default profile as well as a default region to use when creating connections. See Configuration for in-depth configuration sources and options.
Step 2: Create a GlassFlow Pipeline
Log in to GlassFlow WebApp:
Navigate to the GlassFlow WebApp and log in to your account.
Create a New Space:
Go to the “Spaces” page and create a new space named
kinesis-integration
to organize your pipelines.
Create a New Pipeline:
Within the new space, go to the “Pipelines” page and click “Create Pipeline.”
Provide a name for the pipeline, e.g.,
kinesis-to-glassflow
.Choose the space you created (e.g.,
kinesis-integration
).
Configure a Data Source:
Select "SDK". The GlassFlow SDK option requires you to implement the logic for sending data from AWS Kinesis Data Streams to the GlassFlow pipeline in Python.
Add Transformation Stage (Optional):
To transform the incoming data, add a transformation function in GlassFlow.
Create a Python script
transform.py
that defines the logic for analyzing watch frequency from Netflix view metrics.
Configure Data Sink SDK:
Choose a data sink for your processed data. You can use SDK connectors for various data stores.
Configure the sink according to your needs (e.g., database connection details).
Confirm Pipeline Creation:
Review your pipeline configuration and click “Create Pipeline.”
Copy the new Pipeline ID and Access Token for future reference.
Step 3: Setup a Sample Project
Create a folder
Start by creating a dedicated project folder. Create a directory for this project named glassflow-aws-kinesis
, where you will place all the necessary files.
Create a new virtual environment
Create a new virtual environment in the same folder and activate that environment:
Install libraries
Install the GlassFlow, Google Cloud PubSub Python SDKs, and virtual environment package python-dotenv
using pip
.
Create an environment configuration file
Create a .env
file in your project directory with the following content:
Replace placeholders with the actual values from your GlassFlow account and AWS credentials.
Step 4: Generate and Publish Data to AWS Kinesis Stream
Generate sample data stream with Netflix view events and push it to Kinesis using a Python script. It also creates a new Kinesis data stream service in your AWS environment if you do not have an existing one.
Step 5: Consume Data from the GlassFlow pipeline
Create a new Python file called consumer.py
and consume transformed data from the GlassFlow pipeline. The pipeline continuously checks for new data from the Kinesis service, transforms it as needed, and consumes it.
After running the Python script, you will see the transformed data in the console output something like this:
Conclusion
By integrating AWS Kinesis Data Streams with GlassFlow, you can efficiently handle real-time data streams and apply transformations before storing the results in various data sinks. If you need a built-in GlassFlow connector for Amazon Kinesis Data Streams service, raise an issue on GitHub.
Last updated