https://python-poetry.org/docs/#installation
- Login in to AWS and select a region.
- Launch an EC2 instance.
- Name: kafka-stock-market-ec2
- AMI: Amazon Linux 2 AMI (HVM) - Kernel 5.10, SSD Volume Type.
- Instance Type: t2.micro.
- Create a key pair (RSA, .pem) (Store the .pem in your local directory).
- SSH client connect to the EC2 instance..
- First run:
chmod 400 key_name.pem
.
- First run:
wget https://downloads.apache.org/kafka/3.6.2/kafka_2.12-3.6.2.tgz
.- The version may no longer be available.
- Visit https://downloads.apache.org/kafka/ if so.
- Subsequent code will need to be updated to the latest Kafka version.
tar -xvf kafka_2.12-3.6.2.tgz
.sudo yum install java-1.8.0-openjdk
.cd kafka_2.12-3.6.2/
.sudo nano config/server.properties
.- Remove the
#
from#advertised.listeners=PLAINTEXT://your.host.name:9092
- Replace
your.host.name
with the public IPv4 address of the EC2 machineEC2_IPv4_public_address:9092
. control-x
,y
,enter
.bin/zookeeper-server-start.sh config/zookeeper.properties
.- The Zookeeper server is now running.
- Create a new terminal window, ensure the working directory contains the .pem file.
- SSH client connect to the EC2 instance.
export KAFKA_HEAP_OPTS="-Xmx256M -Xms128M"
.cd kafka_2.12-3.6.2/
.bin/kafka-server-start.sh config/server.properties
.- The Kafka server is now running.
- Edit the EC2 instance's security groups inbound rules.
Add rule
.- Type - All Traffic.
- Source - Anywhere-IPv4.
Save rules
.
- Create a new terminal window, ensuring the working directory contains the .pem file.
- SSH client connect to the EC2 instance.
cd kafka_2.12-3.6.2/
.bin/kafka-topics.sh --create --topic demo_test --bootstrap-server EC2_IPv4_public_address:9092 --replication-factor 1 --partitions 1
.
bin/kafka-console-producer.sh --topic demo_test --bootstrap-server EC2_IPv4_public_address:9092
.
- Create a new terminal window, ensuring the working directory contains the .pem file.
- SSH client connect to the EC2 instance.
cd kafka_2.12-3.6.2/
.bin/kafka-console-consumer.sh --topic demo_test --bootstrap-server EC2_IPv4_public_address:9092
.- You can now type within the producer shell and it will be outputted to the consumer shell.
- Login in to AWS and select a region.
- Create an S3 bucket.
- Bucket name: kafka-stock-market-s3-your-name
- AWS Region: Closest to you
- Go to the IAM dashboard and create a new IAM user.
Add users
.- User name: your name-stock-market-data.
- AWS credential type: Access key - Programmatic access.
Attach existing policies directly
: AdminstratorAccess.
- Download the .csv for the Access key ID and the Secret access key.
- Open a new terminal window.
aws configure
.- Input your Access key ID and Secret access key.
- Select the default region closest to you.
- You can now send data from your local PC to the S3 bucket.
- Setup the project as per sections 1 - 4.
- Create a new terminal and type the following:
git clone https://github.com/timiancam/stock_market_data_kafka_ec2_s3.git
.cd stock_market_data_kafka_ec2_s3
.poetry shell
.poetry install
.- Edit the following lines of code in stock_market_script.py:
- Line 17 - Bootstrap Server EC2 Public IPv4 address
- Line 37 - S3 URL address
- Finalize repository metadeta and settings.
- Final check.