#!/bin/bash

# A script to create a Kinesis Data Stream using AWS CLI.

# --- Configuration ---
REGION="us-east-1"
STREAM_NAME="MyCLIKinesisStream"
SHARD_COUNT=1 # Number of shards for the stream

# --- 1. Create Kinesis Data Stream ---
echo "--- Creating Kinesis Data Stream: $STREAM_NAME with $SHARD_COUNT shard(s) ---"
aws kinesis create-stream \
  --stream-name $STREAM_NAME \
  --shard-count $SHARD_COUNT \
  --region $REGION

echo "Kinesis Data Stream created. Waiting for it to become active..."
aws kinesis wait stream-exists-v2 \
  --stream-name $STREAM_NAME \
  --region $REGION

echo "Kinesis Data Stream '$STREAM_NAME' is active."

# --- 2. Output Stream ARN ---
STREAM_ARN=$(aws kinesis describe-stream \
  --stream-name $STREAM_NAME \
  --region $REGION \
  --query 'StreamDescription.StreamARN' --output text)

echo -e "\n--- Kinesis Data Stream Setup Complete! ---"
echo "Stream ARN: $STREAM_ARN"
echo "You can now put records into this stream."

read -p "Press Enter to delete the Kinesis Data Stream..."

# --- Clean Up ---
echo -e "\n--- Deleting Kinesis Data Stream: $STREAM_NAME ---"
aws kinesis delete-stream \
  --stream-name $STREAM_NAME \
  --region $REGION

echo "Waiting for stream to be deleted..."
aws kinesis wait stream-not-exists-v2 \
  --stream-name $STREAM_NAME \
  --region $REGION

echo "Kinesis Data Stream '$STREAM_NAME' deleted successfully."

echo -e "\n--- Kinesis Data Stream demonstration and cleanup complete ---"
