This project uses AWS SAM (Serverless Application Model) to deploy a solution that monitors IP address utilization in specified subnets and sends alerts when utilization exceeds a threshold.
You can find the full article here : https://dev.to/aws-heroes/use-amazon-q-developer-and-aws-infrastructure-composer-to-automate-the-monitoring-of-available-ip-addresses-in-subnets-1hip
- AWS CLI installed and configured with appropriate permissions
- AWS SAM CLI installed
- Python 3.12 installed
-
Clone this repository:
-
Modify the
template.yaml
file to adjust default parameter values or add/remove resources as needed. eg: VPC ID, Subnet Name, Subnet ID, CloudWatch Metric Namespace. -
(Optional) Update the
lambda_function.py
file in thesrc
directory. -
Build the SAM application:
sam build
-
Deploy the SAM application:
sam deploy --guided
This will start an interactive deployment process. You'll be prompted to provide values for the parameters defined in the template. You can accept the default values or provide your own.
-
During the deployment, you'll be asked to confirm the creation of IAM roles and the changes to be applied. Review and confirm these.
-
Once the deployment is complete, SAM will output the ARNs of the created Lambda function and SNS topic.
VpcId
: The ID of the VPC to monitorSubnetIds
: Comma-separated list of subnet IDs to monitorSubnetName1
: Name of the first subnetSubnetName2
: Name of the second subnetCWMetericNamespace
: The CloudWatch metric namespaceAlertEmail
: Email address to receive alerts
- Lambda function for monitoring subnets
- EventBridge rule to trigger the Lambda function every minute
- SNS topic for sending alerts
- CloudWatch alarms for each monitored subnet
- To monitor more than two subnets, duplicate the
SubnetUtilizationAlarm
resource in the template and adjust theSubnetIds
parameter. - Modify the Lambda function code in
src/lambda_function.py
to implement your specific monitoring logic. - Adjust the alarm thresholds and evaluation periods in the
SubnetUtilizationAlarm
resources as needed.
This will start an interactive deployment process. You'll be prompted to provide values for the parameters defined in the template. You can accept the default values or provide your own.
-
During the deployment, you'll be asked to confirm the creation of IAM roles and the changes to be applied. Review and confirm these.
-
Once the deployment is complete, SAM will output the ARNs of the created Lambda function and SNS topic.
VpcId
: The ID of the VPC to monitorSubnetIds
: Comma-separated list of subnet IDs to monitorSubnetName1
: Name of the first subnetSubnetName2
: Name of the second subnetCWMetericNamespace
: The CloudWatch metric namespaceAlertEmail
: Email address to receive alerts
- Lambda function for monitoring subnets
- EventBridge rule to trigger the Lambda function every minute
- SNS topic for sending alerts
- CloudWatch alarms for each monitored subnet
- To monitor more than two subnets, duplicate the
SubnetUtilizationAlarm
resource in the template and adjust theSubnetIds
parameter. - Modify the Lambda function code in
src/lambda_function.py
to implement your specific monitoring logic. - Adjust the alarm thresholds and evaluation periods in the
SubnetUtilizationAlarm
resources as needed.
To remove all resources created by this stack: sam delete
Follow the prompts to confirm the deletion of resources.
For any issues or questions, please open an issue in the GitHub repository.