Skip to content

nijordia/aws-inventory-alert

Repository files navigation

AWS Inventory Alert Pipeline

A serverless inventory monitoring solution that automatically detects low-stock products and sends email alerts using AWS services.

Overview

This project demonstrates a simple yet practical serverless architecture on AWS. When a CSV inventory file is uploaded to an S3 bucket, a Lambda function automatically processes it, identifies products with stock levels below their minimum threshold, and sends an email notification via SNS.

Author: nijordia

Architecture

Architecture Diagram

Flow:

  1. Clerk uploads inventory.csv to S3 bucket
  2. S3 event triggers Lambda function
  3. Lambda reads CSV and checks: current_stock < min_stock
  4. If low stock items found → Lambda publishes alert to SNS
  5. SNS sends email notification to suppliers & manager

Tech Stack

Service Purpose
Amazon S3 Stores uploaded inventory CSV files and triggers Lambda on new uploads
AWS Lambda Serverless compute that processes CSV files and checks stock levels
Amazon SNS Sends email notifications when low stock is detected
AWS CloudFormation Infrastructure as Code for deploying all resources
Python 3.12 Lambda runtime for processing logic

Quick Start

  1. Deploy stack (via Console or CLI)
  2. Confirm SNS subscription in your inbox
  3. Upload example_inventory.csv to the bucket
  4. Check email for low stock alert

Prerequisites

  • AWS Account with appropriate permissions
  • AWS CLI installed and configured
  • Email address for receiving alerts (you'll need to confirm the subscription)

Deployment

Step 1: Clone the Repository

git clone https://github.com/nijordia/aws-inventory-pipeline.git
cd aws-inventory-pipeline

Step 2: Deploy via CloudFormation

Using AWS CLI:

aws cloudformation create-stack \
  --stack-name inventory-alert-pipeline \
  --template-body file://cloudformation-template.yaml \
  --parameters \
    ParameterKey=BucketNamePrefix,ParameterValue=my-inventory \
    ParameterKey=AlertEmail,ParameterValue=your-email@example.com \
  --capabilities CAPABILITY_IAM

Using AWS Console:

  1. Navigate to CloudFormation in the AWS Console
  2. Click Create stackWith new resources
  3. Upload cloudformation-template.yaml
  4. Fill in the parameters:
    • BucketNamePrefix: A unique prefix for your S3 bucket
    • AlertEmail: Your email address for receiving alerts
  5. Acknowledge IAM resource creation
  6. Click Create stack

Step 3: Confirm Email Subscription

After deployment, check your email inbox for a subscription confirmation from AWS SNS. Click the confirmation link to activate alerts.

Step 4: Test the Pipeline

Upload the example CSV to your S3 bucket:

aws s3 cp example_inventory.csv s3://<your-bucket-name>/inventory.csv

Or upload via the AWS Console S3 interface.

CSV Format

The inventory CSV must have the following columns:

Column Description
product Product name or identifier
current_stock Current quantity in stock
min_stock Minimum threshold for alerts

Example:

product,current_stock,min_stock
Widget A,50,20
Widget B,5,10
Gadget X,100,25

Screenshots

1. CloudFormation Deployment

Stack successfully deployed with CREATE_COMPLETE status, showing all resources provisioned:

CloudFormation Stack

2. SNS Subscription Confirmation

Email received to confirm subscription to the alert topic:

SNS Subscription

3. Low Stock Alert Email

Alert triggered after uploading inventory CSV with items below minimum stock:

Low Stock Alert

Project Structure

aws-inventory-pipeline/
├── README.md                      # Project documentation
├── cloudformation-template.yaml   # IaC template for all AWS resources
├── lambda_code/
│   └── inventory_alert.py         # Lambda function source code
├── example_inventory.csv          # Sample CSV for testing
├── images/
│   └── diagram.png                # Architecture diagram
└── screenshots/                   # Documentation screenshots
    ├── CloudFormation.png
    ├── SNS_suscription.png
    └── Email _alert.png

How It Works

  1. S3 Event Notification: When a .csv file is uploaded to the S3 bucket, an event notification triggers the Lambda function.

  2. CSV Processing: The Lambda function:

    • Downloads the CSV file from S3
    • Parses each row to extract product, current_stock, and min_stock
    • Identifies products where current_stock < min_stock
  3. Alert Generation: If low-stock products are found:

    • Formats a human-readable alert message
    • Publishes the message to the SNS topic
    • SNS delivers the email to all confirmed subscribers
  4. Error Handling: The Lambda function includes error handling for:

    • Invalid CSV format
    • Missing columns
    • Non-numeric stock values
    • S3 access issues

Cost Estimation

This solution uses AWS Free Tier eligible services:

  • S3: 5GB storage, 20,000 GET requests, 2,000 PUT requests/month free
  • Lambda: 1M requests, 400,000 GB-seconds/month free
  • SNS: 1,000 email notifications/month free

For typical inventory monitoring usage, this solution should operate within the Free Tier.

Cleanup

To delete all resources and avoid charges:

# First, empty the S3 bucket
aws s3 rm s3://<your-bucket-name> --recursive

# Then delete the CloudFormation stack
aws cloudformation delete-stack --stack-name inventory-alert-pipeline

Future Enhancements

  • Add DynamoDB for historical tracking
  • Implement multiple alert thresholds (warning/critical)
  • Add Slack/Teams webhook integration
  • Create a web dashboard with API Gateway
  • Add support for Excel files

License

MIT License - feel free to use this project for learning or as a starting point for your own solutions.


Questions or feedback? Open an issue on GitHub.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages