dynamodb.service.tsā¢2.05 kB
import {
CreateTableCommand,
DeleteTableCommand,
DescribeTableCommand
} from '@aws-sdk/client-dynamodb';
import { dynamoDBClient } from '../../config/aws.config';
import { logger } from '../../utils/logger';
export class DynamoDBService {
async createTable(parameters: any) {
try {
const tableName = parameters.tableName || `mcp-table-${Date.now()}`;
const command = new CreateTableCommand({
TableName: tableName,
KeySchema: [
{
AttributeName: parameters.partitionKey || 'id',
KeyType: 'HASH',
},
],
AttributeDefinitions: [
{
AttributeName: parameters.partitionKey || 'id',
AttributeType: 'S',
},
],
BillingMode: 'PAY_PER_REQUEST',
Tags: [
{ Key: 'CreatedBy', Value: 'MCP-Infrastructure' },
{ Key: 'Environment', Value: parameters.environment || 'development' },
],
});
const response = await dynamoDBClient.send(command);
logger.info(`Created DynamoDB table: ${tableName}`);
return { tableName, details: response.TableDescription };
} catch (error) {
logger.error('Error creating DynamoDB table:', error);
throw error;
}
}
async deleteTable(tableName: string) {
try {
const command = new DeleteTableCommand({
TableName: tableName,
});
await dynamoDBClient.send(command);
logger.info(`Deleted DynamoDB table: ${tableName}`);
return { success: true };
} catch (error) {
logger.error('Error deleting DynamoDB table:', error);
throw error;
}
}
async getTableStatus(tableName: string) {
try {
const command = new DescribeTableCommand({
TableName: tableName,
});
const response = await dynamoDBClient.send(command);
// Corrected: Access Table property directly
return response.Table; //
} catch (error) {
logger.error('Error getting table status:', error);
throw error;
}
}
}