This application monitors 3D prints in real-time by capturing frames from an RTSP stream, analyzing them using AWS Bedrock's AI capabilities, and sending notifications through Discord and MQTT. It's designed to detect print failures (like spaghetti) and provide immediate alerts through your preferred notification channels.
Ensure you have the necessary AWS credentials file and RTSP stream URL.
Configure the application using the docker-compose.yml file.
docker compose up -d
docker compose logs -f
docker compose down
The application can be configured using environment variables in the docker-compose.yml file:
| Variable | Description | Required | Default |
|---|---|---|---|
RTSP_URL | URL of the RTSP stream to analyze | Yes | - |
DISCORD_WEBHOOK_URL | Discord webhook URL for notifications | No | - |
AWS_REGION | AWS region for Bedrock service | No | us-west-2 |
AWS_ROLE_ARN | ARN of the AWS role to assume | Yes | - |
INFERENCE_PROFILE_ARN | ARN of the Bedrock inference profile | Yes | - |
TEST_MODE | Enable test mode (processes single frame) | No | false |
VERBOSE_LOGGING | Enable verbose logging | No | false |
APP_AWS_PROFILE | AWS profile name to use for credentials | No | default |
ANALYSIS_INTERVAL | Interval between frame analysis in seconds | No | 10 |
MQTT_BROKER_URL | URL of the MQTT broker | No | - |
MQTT_TOPIC | MQTT topic for status updates | No | - |
To enable Discord notifications, set the DISCORD_WEBHOOK_URL environment variable in your docker-compose.yml:
environment:
- DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/your-webhook-url
If this variable is not set, the application will skip sending notifications to Discord.
When MQTT is configured, the application will publish status updates to the specified topic. Each message is a JSON object with the following structure:
{
"timestamp": "2024-05-16T17:34:42.123456",
"print_failed": true,
"description": "Print failure was detected in the image."
}
The status is published every time a frame is analyzed, regardless of whether a Discord notification is sent. This allows other systems to monitor the print status in real-time.
The AWS credentials file is mounted into the Docker container as a read-only file. This is done by specifying the path to the credentials file on the host and the path inside the container where it will be mounted. The :ro suffix ensures that the file is mounted as read-only.
The ANALYSIS_INTERVAL variable can be used to optimize AWS costs. For example:
ANALYSIS_INTERVAL=30 will reduce AWS Bedrock API calls by 66%ANALYSIS_INTERVAL=60 will reduce AWS Bedrock API calls by 83%Choose an interval that balances your need for timely failure detection with your AWS cost requirements.
When TEST_MODE is set to true, the application will not automatically process frames. Instead, it will wait for a manual trigger. You can trigger the workflow manually using the following one-liner:
docker exec -it rtsp-bedrock-discord python -c "from app import process_frame; process_frame()"
Set VERBOSE_LOGGING to true in the docker-compose.yml file to enable detailed logging. This will output additional information about the application's operations, such as frame capture, image encoding, and analysis results.
You can generate the credentials file using the provided write-temp-creds.sh script. This script fetches temporary credentials for a given AWS profile (using tools like aws-vault and pass) and writes them to the specified output directory in the required format.
./write-temp-creds.sh <profile-name>
This will create or update your credentials file with a section for the specified profile. You can then mount this file into the container and select the profile using the APP_AWS_PROFILE environment variable as described above.
For more information on aws-vault, visit the official documentation.
This application uses AWS credentials from a mounted credentials file (e.g., /creds/credentials). You can specify multiple profiles in this file, similar to the standard AWS credentials format:
[default]
aws_access_key_id=AKIAXXXXXXXXXXXXXXXX
aws_secret_access_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
aws_session_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[vault-user]
aws_access_key_id=AKIAYYYYYYYYYYYYYYYY
aws_secret_access_key=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
aws_session_token=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
(You can generate this file using the write-temp-creds.sh script as described above.)
To select which profile to use, set the APP_AWS_PROFILE environment variable in your docker-compose.yml:
environment:
- APP_AWS_PROFILE=vault-user
Important:
AWS_PROFILE environment variable. If you do, boto3/botocore will try to load the profile from the default AWS credentials/config location (e.g., ~/.aws/credentials), not from your mounted file. This will cause errors if the profile does not exist there.APP_AWS_PROFILE variable and selects the correct profile from your mounted credentials file internally.APP_AWS_PROFILE to select the profile from your mounted credentials file.AWS_PROFILE in the environment.The application uses AWS credentials to assume a role specified by AWS_ROLE_ARN. This role must have the necessary permissions to access AWS Bedrock and perform the required operations.
The assumed role should have the following permissions:
bedrock:InvokeModel: To invoke the AWS Bedrock model for image analysis.sts:AssumeRole: To allow the application to assume the specified role.The user running the application should have the following permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::your-account-id:role/your-role-name"
}
]
}
The role to be assumed should have the following permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "bedrock:InvokeModel",
"Resource": "arn:aws:bedrock:us-west-2:your-account-id:inference-profile/your-profile"
}
]
}
The trust policy for the role should allow the user to assume the role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::your-account-id:user/your-user-name"
},
"Action": "sts:AssumeRole"
}
]
}
User Credentials: The application uses the AWS credentials of the user running the application to authenticate with AWS.
Role Assumption: The application assumes the role specified by AWS_ROLE_ARN using the AWS Security Token Service (STS). This allows the application to perform actions as if it were the assumed role.
Access AWS Bedrock: With the assumed role, the application can access AWS Bedrock to analyze images and detect print failures.
For more information on AWS IAM roles and permissions, visit the AWS IAM documentation.
Content type
Image
Digest
sha256:c311e9d3b…
Size
228.8 MB
Last updated
about 2 months ago
docker pull chuckcharlie/awspaghetti