Feat: Adds cognito and memory

This commit is contained in:
2025-10-22 11:24:38 -03:00
parent f71b054dca
commit d37d5132eb
45 changed files with 3983 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
import boto3
def write_memory(user,timestamp,role,content):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('assistente-produtos-servicos-memoria') # Replace 'YourTableName' with your actual table name
item_data = {
'UserId': user, # Replace with your partition key attribute and value
'Timestamp': timestamp, # Replace with your sort key attribute and value (if applicable)
'role': role,
'content': content
}
try:
response = table.put_item(Item=item_data)
except Exception as e:
print("Error adding item:", e)
def read_memory(userid):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('assistente-produtos-servicos-memoria')
# Query parameters
try:
response = table.query(
KeyConditionExpression=boto3.dynamodb.conditions.Key('UserId').eq(userid),
ScanIndexForward=False, # Descending order
Limit=30
)
items = response.get('Items', [])
if items:
latest_items = items
return latest_items
else:
return []
except Exception as e:
print("Error querying DynamoDB:", str(e))

View File

@@ -0,0 +1,25 @@
import boto3
from botocore.exceptions import ClientError
def get_secret():
secret_name = "assistente-produtos-servicos"
region_name = "us-east-1"
# Create a Secrets Manager client
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=region_name
)
try:
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
except ClientError as e:
# For a list of exceptions thrown, see
# https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
raise e
secret = get_secret_value_response['SecretString']
return secret