Skip to content

Commit b85d031

Browse files
struct kb
1 parent 1a09d73 commit b85d031

15 files changed

Lines changed: 415 additions & 0 deletions

structured-kb-demo/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

structured-kb-demo/README.md

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import boto3
2+
3+
from logger import logger
4+
from vars import DB_NAME, REGION
5+
6+
glue = boto3.client('glue', region_name=REGION)
7+
8+
try:
9+
response = glue.create_database(
10+
DatabaseInput={
11+
'Name': DB_NAME,
12+
'Description': 'Database for Bedrock structured knowledge base demo',
13+
}
14+
)
15+
logger.info(f"Glue database '{DB_NAME}' created successfully.")
16+
17+
except glue.exceptions.AlreadyExistsException:
18+
logger.error(f"Database {DB_NAME} already exists.")
19+
except Exception as e:
20+
logger.error(f"Error creating Glue database: {e}")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from logger import logger
2+
3+
import boto3
4+
from botocore.exceptions import ClientError
5+
6+
from vars import BUCKET_NAME, REGION
7+
8+
s3_client = boto3.client('s3', region_name=REGION)
9+
10+
try:
11+
s3_client.head_bucket(Bucket=BUCKET_NAME)
12+
except ClientError as e:
13+
logger.error(f"Error accessing bucket {BUCKET_NAME}: {e}")
14+
s3_client.create_bucket(
15+
Bucket=BUCKET_NAME,
16+
CreateBucketConfiguration={'LocationConstraint': AWS_REGION}
17+
)
18+
logger.info(f"Bucket {BUCKET_NAME} created successfully")
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import json
2+
3+
import boto3
4+
5+
from logger import logger
6+
from vars import BUCKET_ARN, QUEUE_NAME, QUEUE_ARN
7+
8+
sqs = boto3.client('sqs')
9+
10+
access_policy = {
11+
"Statement": [
12+
{
13+
"Effect": "Allow",
14+
"Principal": {
15+
"Service": "s3.amazonaws.com"
16+
},
17+
"Action": "sqs:SendMessage",
18+
"Resource": QUEUE_ARN,
19+
"Condition": {
20+
"ArnLike": {
21+
"aws:SourceArn": BUCKET_ARN
22+
}
23+
}
24+
}
25+
]
26+
}
27+
28+
try:
29+
# Check if queue exists
30+
sqs.get_queue_url(QueueName=QUEUE_NAME)
31+
logger.info(f"Queue already exists.")
32+
except sqs.exceptions.QueueDoesNotExist:
33+
# Create queue if it doesn't exist
34+
sqs.create_queue(
35+
QueueName=QUEUE_NAME,
36+
Attributes={
37+
'Policy': json.dumps(access_policy)
38+
}
39+
)
40+
logger.info(f"Queue created successfully.")
41+
except Exception as e:
42+
logger.error(f"Error: {e}")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource_id,service,region,status,monthly_cost,owner_team
2+
i-01,EC2,us-east-1,running,45.0,DevOps
3+
i-02,EC2,us-west-2,stopped,0.0,DevOps
4+
db-01,RDS,ap-south-1,available,120.0,Data-Science
5+
db-02,RDS,us-east-1,backing-up,95.0,Data-Science
6+
vol-01,EBS,us-east-1,attached,10.5,DevOps
7+
s3-01,S3,eu-west-1,active,5.25,Security
8+
s3-02,S3,us-east-1,active,55.0,Marketing
9+
elb-01,ALB,us-east-1,active,22.0,DevOps
10+
cf-01,CloudFront,global,deployed,15.0,Marketing
11+
sqs-01,SQS,us-east-1,active,1.2,DevOps
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource_id,service,region,status,monthly_cost,owner_team,environment
2+
lambda-01,Lambda,us-east-1,active,0.5,DevOps,Production
3+
lambda-02,Lambda,us-east-1,active,0.1,DevOps,Staging
4+
db-03,RDS,ap-south-1,available,150.0,Data-Science,Production
5+
i-03,EC2,us-east-1,running,45.0,Interns,Development
6+
i-04,EC2,us-east-1,running,45.0,Interns,Development
7+
s3-03,S3,us-east-1,active,12.0,Sales,Production
8+
eks-01,EKS,us-east-1,active,73.0,DevOps,Production
9+
redshift-01,Redshift,us-east-1,available,350.0,Analytics,Production
10+
sns-01,SNS,us-east-1,active,0.8,DevOps,Production
11+
glue-01,Glue,us-east-1,idle,0.0,DevOps,Staging

structured-kb-demo/logger.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import logging
2+
3+
logging.basicConfig(level=logging.INFO)
4+
logger = logging.getLogger(__name__)

structured-kb-demo/pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "structured-kb-demo"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"boto3>=1.42.97",
9+
"python-dotenv>=1.2.2",
10+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import boto3
2+
3+
from logger import logger
4+
from vars import BUCKET_NAME, QUEUE_ARN
5+
6+
s3 = boto3.client("s3")
7+
8+
notification_configuration = {
9+
"QueueConfigurations": [
10+
{
11+
"QueueArn": QUEUE_ARN,
12+
"Events": [
13+
"s3:ObjectCreated:*",
14+
"s3:ObjectRemoved:*"
15+
]
16+
}
17+
]
18+
}
19+
20+
try:
21+
s3.put_bucket_notification_configuration(
22+
Bucket=BUCKET_NAME,
23+
NotificationConfiguration=notification_configuration
24+
)
25+
print(f"Successfully added event notifications to {BUCKET_NAME}")
26+
except Exception as e:
27+
print(f"Error: {e}")

0 commit comments

Comments
 (0)