95 lines
4.0 KiB
Markdown
95 lines
4.0 KiB
Markdown
# Amazon Rekognition People Label Detection via KVS
|
|
This is the README for the whole people detection pipeline designed for real-time video analysis.
|
|
|
|
There are three Lambda functions placed inside this repository:
|
|
### 1. Kinesis Video Stream to Rekognition (`cctv-people-rekogniton`)
|
|
This function utilizes Amazon Rekognition's stream processor, which is configured to monitor an incoming Amazon Kinesis Video Stream for people label detection.
|
|
|
|
Note that this Lambda function is intended to process **a single Kinesis video stream only**. For a multi-camera setup, multiple deployments of this Lambda function are necessary.
|
|
|
|
This is built on top of AWS KVS Consumer Library for Python. The original repository can be found here: https://github.com/aws-samples/amazon-kinesis-video-streams-consumer-library-for-python/
|
|
|
|
### 2. SNS to DynamoDB and OpenSearch (`cctv-people-sns-dynamodb`)
|
|
This function writes a new entry to DynamoDB and Opensearch tables whenever there is a detection coming from Rekognition via SNS.
|
|
|
|
### 3. DynamoDB to Supabase (`cctv-people-dynamodb-supabase`)
|
|
This function acts an extension of the previous function, writing a new entry to Supabase whenever there is a new entry in DynamoDB.
|
|
|
|
## Prerequites
|
|
The following must already be set up before deploying this pipeline:
|
|
1. A working Kinesis video stream as input
|
|
2. An S3 Bucket where all frames with detection go
|
|
3. A SNS topic that will receive the notification coming from Rekognition
|
|
4. A DynamoDB table
|
|
5. An OpenSearch Service collection
|
|
|
|
It is advised to have all above components in the same region for easy configuration.
|
|
|
|
## Setup
|
|
### Part I. Kinesis Video Stream to Rekognition (`\cctv-people-rekogniton`)
|
|
|
|
1. Create an IAM role for the Rekognition stream processor. This role must contain the following AWS-managed policies:
|
|
- AmazonRekognitionServiceRole
|
|
- AmazonS3FullAccess
|
|
|
|
2. Provide the following details in `lambda_function.py`:
|
|
- Kinesis video stream name and ARN
|
|
- Stream processor name (must be unique to the KVS stream)
|
|
- S3 bucket name
|
|
- IAM role ARN
|
|
- SNS topic ARN
|
|
|
|
3. Package the folder as a ZIP file.
|
|
4. Create an AWS Lambda function and upload the ZIP file.
|
|
5. Add an EventBridge trigger with the schedule expression of `rate(5 minutes)`
|
|
|
|
### Part II. SNS to DynamoDB and OpenSearch (`\cctv-people-sns-dynamodb`)
|
|
|
|
1. Create a Lambda function and upload the `lambda_function.py` file.
|
|
2. Add a trigger to receive notifications from the SNS topic.
|
|
3. Add the following AWS-managed permissions to this Lambda function:
|
|
- AmazonDynamoDBFullAccess_v2
|
|
- AmazonOpenSearchIngestionFullAccess
|
|
- AmazonOpenSearchServiceFullAccess
|
|
- AmazonS3FullAccess
|
|
4. Add an inline policy for OpenSearch Serverless:
|
|
```
|
|
{
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Sid": "Statement1",
|
|
"Effect": "Allow",
|
|
"Action": "aoss:*",
|
|
"Resource": "*"
|
|
}
|
|
]
|
|
}
|
|
```
|
|
5. Create an AWS Managed Grafana workspace.
|
|

|
|

|
|
|
|
6. Access the workspace and install opensearch aws sig4 and opensearch extension.
|
|
|
|

|
|

|
|
|
|
7. Point it to the opensearch url and make sure Aws SigV4 is enabled.
|
|
Configure the correct index.
|
|
|
|
### 3. DynamoDB to Supabase (`\cctv-people-dynamodb-supabase`)
|
|
1. On a local machine, prepare a folder for Supabase installation.
|
|
2. Open a terminal pointed at this directory and run the following command:
|
|
```
|
|
pip3 install supabase --platform manylinux2014_x86_64 --python-version 3.12 --only-binary=:all: -t .
|
|
```
|
|
3. Place the `lambda_function.py` inside this folder.
|
|
4. Package the folder as a ZIP file.
|
|
5. Create an AWS Lambda function and upload the ZIP file.
|
|
6. Add the following AWS-managed permission to the IAM role for this Lambda:
|
|
- AmazonDynamoDBFullAccess_v2
|
|
7. Enable stream on the DynamoDB table. Set view type to **New image**.
|
|
8. Add trigger to the Lambda function to connect to the DynamoDB stream.
|
|
|