AWS Builder Center
Build a tool to detect outdated applications with Amazon Bedrock

Build a tool to detect outdated applications with Amazon Bedrock

How to build a CloudWatch analysis tool using only prompts with Amazon Bedrock

This blog details how to use Amazon Bedrock to create an intelligent system for detecting and managing outdated applications and modules.

The Challenge

Many organizations struggle with keeping their software up-to-date across large, distributed systems. Manual monitoring is time-consuming and error-prone, while existing automated solutions often lack the context needed for informed decision-making. Below solution that not only detects outdated software but also provides intelligent, actionable insights for remediation.

The Solution

This solution combines several AWS services, including CloudWatch, Lambda, Bedrock, and SNS, to create a fully automated update management system. Here's how I built it, step by step, using Amazon Bedrock's Claude model to guide my development process.
Step 1: Defining the System Architecture
I began by outlining the basic structure of my system. Using Bedrock, I prompted:
"I would like you to create a notification system that crawls CloudWatch logs and looks for out of date modules or applications then creates an alerting system that sends an administrator an email or SMS"
Claude provided a high-level overview and sample Python code for a Lambda function that crawls CloudWatch logs, searches for patterns indicating outdated modules, and sends notifications via SNS.
Step 2: Enhancing with Bedrock Analysis
To make my system more intelligent, I asked Claude to refine the solution:
"I would like to you refine this so that it leverages bedrock to check whether an application is out of date and also give a detailed human readable explanation how to resolve this"
Step 3: Adding Sample Inputs and Outputs
To better understand how the system would work in practice, I requested sample inputs and outputs:
"Please add sample inputs and outputs"
Claude provided example CloudWatch log messages and a detailed sample output from the Bedrock analysis. This helped us visualize the end-to-end process and the level of detail my system could provide to administrators.
Step 4: Creating a System Diagram
To clarify the system's architecture, I asked Claude to create a diagram:
"Create a diagram of the flow for this system"
While Claude can't generate images directly, it provided a detailed text description of the system flow, which I used to create a visual diagram. This step was crucial for understanding and communicating the system's components and their interactions.
The output is below
+-------------------+
| CloudWatch Logs |
| (Application |
| Log Groups) |
+--------+----------+
|
| Log data
v
+-------------------+
| CloudWatch Events |
| (Scheduled rule) |
+--------+----------+
|
| Triggers periodically
v
+-------------------+
| Lambda Function |
+--------+----------+
|
| 1. Fetch logs
v
+-------------------+
| Log Analysis |
| (Pattern Matching)|
+--------+----------+
|
| 2. Detected outdated items
v
+-------------------+
| Amazon Bedrock |
| (Claude AI Model) |
+--------+----------+
|
| 3. AI analysis and recommendations
v
+-------------------+
| SNS Topic |
+--------+----------+
|
| 4. Notification
v
+-------------------+
| Admin (Email/SMS) |
+-------------------+
Step 5: Framing the Solution for AWS Customers
Finally, to position my solution effectively, I asked Claude to assume the role of an AWS Solutions Architect:
"assume the role of an aws solutions architect, please write an introduction for the solution above, detailing the problem and why this solution will help aws customers"
Claude provided a comprehensive introduction that outlined the challenges addressed by my solution and its specific benefits to AWS customers. This helped frame the solution in the context of real-world cloud management challenges.

Implementation Details

The heart of my solution is a Lambda function that periodically scans CloudWatch logs for indications of outdated software. When potential issues are detected, it leverages the Claude model in Amazon Bedrock to perform an in-depth analysis. Here's a key excerpt from my Lambda function:
def analyze_with_bedrock(items, bedrock_client):
prompt = f"""
Analyze the following log messages indicating outdated applications or modules:
{json.dumps(items, indent=2)}
For each item:
1. Confirm if it's truly outdated or if it's a false positive.
2. If outdated, explain why it's important to update.
3. Provide detailed steps to resolve the issue, including potential risks and best practices.
4. Suggest any additional checks or actions the admin should take.
Format your response as a detailed report suitable for a system administrator.
"""
body = json.dumps({
"prompt": prompt,
"max_tokens_to_sample": 2000,
"temperature": 0.5,
"top_p": 0.9,
})
response = bedrock_client.invoke_model(
modelId="anthropic.claude-v2",
contentType="application/json",
accept="application/json",
body=body
)
response_body = json.loads(response.get('body').read())
return response_body.get('completion')
This function sends detected log messages to Bedrock for analysis, receiving in return a detailed report that includes confirmation of outdated status, explanation of update importance, step-by-step resolution instructions, and additional recommendations.

Sample input and output

Sample Input (CloudWatch Log Messages):
2023-11-15 10:23:45 [WARN] Outdated module detected: numpy version 1.19.5 is in use, but 1.26.0 is available.
2023-11-15 11:34:56 [ERROR] Version mismatch: Django 2.2.28 is no longer supported. Upgrade to 4.2 or higher recommended.
2023-11-15 14:45:12 [WARN] Update required: OpenSSL 1.1.1 will reach end-of-life soon. Upgrade to OpenSSL 3.0 advised.
These log messages would be detected by my Lambda function. The function would then send these to Bedrock for analysis. Here's what the output might look like:
Sample Output (Bedrock Analysis):
Detailed Analysis of Outdated Applications and Modules

1. numpy version 1.19.5
Status: Confirmed Outdated
Importance: Medium
The numpy library version 1.19.5 is outdated. The current version is 1.26.0. Updating is important because:
- Newer versions often include performance improvements and bug fixes.
- Some newer Python features or other library dependencies may require a more recent numpy version.
Resolution Steps:
1. Create a virtual environment for your project if not already using one.
2. Update numpy using pip:
pip install --upgrade numpy
3. Test your application thoroughly after the update, as some function behaviors might have changed.
4. Update any requirements.txt or setup.py files to reflect the new version.
Additional Checks:
- Review the numpy changelog to understand any breaking changes.
- Check if other dependencies in your project rely on specific numpy versions.

2. Django 2.2.28
Status: Confirmed Outdated
Importance: High
Django 2.2.28 is significantly outdated and no longer supported. This is a critical security risk.
Resolution Steps:
1. Back up your entire project, including the database.
2. Review the Django upgrade guide for 3.x and 4.x versions.
3. Update your Django version:
pip install Django==4.2.7
4. Run python manage.py makemigrations and python manage.py migrate
5. Update your code to be compatible with Django 4.2, focusing on deprecated features.
6. Run your test suite and fix any issues.
7. Deploy in a staging environment before pushing to production.
Additional Checks:
- Ensure all your third-party Django apps are compatible with Django 4.2.
- Review security settings and middleware configurations.
- Update your deployment scripts or Docker configurations if applicable.

3. OpenSSL 1.1.1
Status: Update Recommended
Importance: High
OpenSSL 1.1.1 will reach end-of-life on September 11, 2023. Upgrading to OpenSSL 3.0 is crucial for ongoing security support.
Resolution Steps:
1. Check your operating system's package manager for OpenSSL updates.
2. For Ubuntu/Debian: sudo apt update && sudo apt upgrade openssl
3. For CentOS/RHEL: sudo yum update openssl
4. If compiling from source, download OpenSSL 3.0 from the official website and follow compilation instructions.
5. After updating, restart any services that depend on OpenSSL (e.g., web servers, database servers).
6. Update any applications that link against OpenSSL and recompile if necessary.
Additional Checks:
- Verify the new OpenSSL version: openssl version
- Review your SSL/TLS configurations for any deprecated settings.
- Test all SSL/TLS connections in your applications.
- Update your security policies and documentation to reflect the new version.

General Recommendations:
1. Implement a regular update schedule for all dependencies and libraries.
2. Use tools like dependabot or renovate to automate dependency updates.
3. Maintain a test environment that mirrors production for safe testing of updates.
4. Keep an inventory of all software versions in use and their support lifecycles.
5. Subscribe to security mailing lists for critical components in your stack.

Please review these recommendations and proceed with updates cautiously, especially in production environments. Always test thoroughly in a staging environment before applying updates to production systems.
Fully functioning CloudFormation template with the solution, generated using Amazon Bedrock (no coding required)
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Intelligent Application Update Management System'

Parameters:
LogGroupName:
Type: String
Description: 'Name of the CloudWatch Log Group to monitor'
AdminEmail:
Type: String
Description: 'Email address for receiving notifications'

Resources:
LambdaExecutionRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: 'sts:AssumeRole'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
Policies:
- PolicyName: LambdaPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'logs:FilterLogEvents'
- 'logs:DescribeLogGroups'
Resource: !Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${LogGroupName}:*'
- Effect: Allow
Action:
- 'sns:Publish'
Resource: !Ref SNSTopic
- Effect: Allow
Action:
- 'bedrock:InvokeModel'
Resource: '*'

LambdaFunction:
Type: 'AWS::Lambda::Function'
Properties:
Handler: index.lambda_handler
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: python3.9
Timeout: 300
MemorySize: 256
Environment:
Variables:
LOG_GROUP_NAME: !Ref LogGroupName
SNS_TOPIC_ARN: !Ref SNSTopic
Code:
ZipFile: |
import boto3
import json
import os
from datetime import datetime, timedelta

def lambda_handler(event, context):
logs_client = boto3.client('logs')
sns_client = boto3.client('sns')
bedrock_client = boto3.client('bedrock-runtime')
log_group_name = os.environ['LOG_GROUP_NAME']
sns_topic_arn = os.environ['SNS_TOPIC_ARN']
time_period = 24
start_time = int((datetime.now() - timedelta(hours=time_period)).timestamp() * 1000)
end_time = int(datetime.now().timestamp() * 1000)
patterns = [
'outdated module',
'version mismatch',
'update required'
]
outdated_items = []
for pattern in patterns:
response = logs_client.filter_log_events(
logGroupName=log_group_name,
startTime=start_time,
endTime=end_time,
filterPattern=pattern
)
for event in response['events']:
outdated_items.append(event['message'])
if outdated_items:
detailed_report = analyze_with_bedrock(outdated_items, bedrock_client)
sns_client.publish(
TopicArn=sns_topic_arn,
Message=detailed_report,
Subject='Outdated Modules/Applications Alert with Resolution Steps'
)
return {
'statusCode': 200,
'body': f'Processed {len(outdated_items)} outdated items'
}

def analyze_with_bedrock(items, bedrock_client):
prompt = f"""
Analyze the following log messages indicating outdated applications or modules:
{json.dumps(items, indent=2)}
For each item:
1. Confirm if it's truly outdated or if it's a false positive.
2. If outdated, explain why it's important to update.
3. Provide detailed steps to resolve the issue, including potential risks and best practices.
4. Suggest any additional checks or actions the admin should take.
Format your response as a detailed report suitable for a system administrator.
"""
body = json.dumps({
"prompt": prompt,
"max_tokens_to_sample": 2000,
"temperature": 0.5,
"top_p": 0.9,
})
response = bedrock_client.invoke_model(
modelId="anthropic.claude-v2",
contentType="application/json",
accept="application/json",
body=body
)
response_body = json.loads(response.get('body').read())
return response_body.get('completion')

CloudWatchEvent:
Type: 'AWS::Events::Rule'
Properties:
Description: 'Schedule for running the Outdated Application Detection Lambda'
ScheduleExpression: 'rate(1 day)'
State: 'ENABLED'
Targets:
- Arn: !GetAtt LambdaFunction.Arn
Id: 'TargetLambdaFunction'

LambdaInvokePermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !Ref LambdaFunction
Action: 'lambda:InvokeFunction'
Principal: 'events.amazonaws.com'
SourceArn: !GetAtt CloudWatchEvent.Arn

SNSTopic:
Type: 'AWS::SNS::Topic'
Properties:
DisplayName: 'Outdated Application Alerts'

SNSSubscription:
Type: 'AWS::SNS::Subscription'
Properties:
TopicArn: !Ref SNSTopic
Protocol: 'email'
Endpoint: !Ref AdminEmail

Outputs:
LambdaFunctionArn:
Description: 'ARN of the Lambda Function'
Value: !GetAtt LambdaFunction.Arn
SNSTopicArn:
Description: 'ARN of the SNS Topic'
Value: !Ref SNSTopic
The full code solution with implementation guide is posted on my GitHub here:  https://github.com/johncattrall/intelligent-application-update-management-system 

Conclusion

By leveraging Amazon Bedrock and other AWS services, I've created an intelligent system that not only detects outdated software but provides contextual, actionable information for remediation. This solution demonstrates the power of combining traditional cloud services with AI capabilities to solve complex operational challenges.
I encourage you to explore how you can integrate similar AI-powered solutions into your own AWS environments. The possibilities are endless, and I'm excited to see what you'll build next!
This blog post outlines the development process, highlighting how Amazon Bedrock was used at each step to guide the creation of the solution. It provides a mix of high-level overview and technical details, making it suitable for a wide range of AWS blog readers.  
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article