Stay on top of your AWS VPN connections with this automated monitoring solution! π― This script is designed to monitor your AWS Site-to-Site VPN tunnels, sending out real-time alerts π¨ via Slack and/or Discord while logging the connection status in DynamoDB π.
- π΅οΈ Real-Time Monitoring: Keep track of your VPN tunnel status with automatic checks.
- π¬ Instant Notifications: Receive alerts on Slack or Discord when something goes wrong.
- π DynamoDB Integration: Store and update the connection status for future reference.
- π οΈ Debug Mode: Easily toggle debug logs to see what's happening behind the scenes.
To get started, make sure you have the following:
- β AWS Lambda setup.
- β AWS DynamoDB table for storing connection statuses.
- β Slack or Discord webhooks for notifications.
- β Appropriate IAM permissions (see below).
Don't forget to attach the following IAM policy to your Lambda execution role for permissions to interact with EC2 and DynamoDB:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeVpnConnections"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"dynamodb:CreateTable",
"dynamodb:DescribeTable",
"dynamodb:PutItem",
"dynamodb:GetItem",
"dynamodb:UpdateItem"
],
"Resource": "arn:aws:dynamodb:*:*:table/*"
}
]
}You'll need to configure the following environment variables in your Lambda function:
- TUNNEL1_IP β The IP address of VPN Tunnel 1 π
- TUNNEL2_IP β The IP address of VPN Tunnel 2 π
- SLACK_WEBHOOK β Slack Webhook URL for notifications π©
- DISCORD_WEBHOOK β Discord Webhook URL for notifications π©
- DYNAMODB_TABLE_NAME β The name of your DynamoDB table ποΈ
- DEBUG β Set to true to enable debug mode π
Package and deploy the script to AWS Lambda using your preferred method (e.g., AWS SAM, Serverless Framework, etc.).
Ensure a DynamoDB table exists with the correct structure to store VPN statuses. The script will automatically create the table if it doesn't already exist. π οΈ Usage
This script will periodically check the status of your VPN tunnels (both Tunnel 1 and Tunnel 2) π΅οΈββοΈ. If any of the tunnels go down, you will be instantly notified via your configured Slack and/or Discord channels π¨. Additionally, the connection status will be stored in DynamoDB π for reference. π Debugging Mode
If you want to see detailed logs while the script runs, set the DEBUG environment variable to true. This will output helpful information for troubleshooting issues π. π How It Works
- Monitoring: The script uses AWS EC2's DescribeVpnConnections API to monitor VPN onnections in real-time.
- Notifications: If a tunnel goes down, the script sends notifications to Slack or iscord.
- DynamoDB Storage: The current status of the VPN connections is stored in a ynamoDB table for persistence.
This project is licensed under the MIT License. See the LICENSE file for details.
Happy monitoring! ππ