Skip to content

Commit

Permalink
feat: added parsing of DynamoDB from boto3 spec with rendering table,…
Browse files Browse the repository at this point in the history
… stream, schema, lsi, gsi, attributes
  • Loading branch information
tsypuk committed May 16, 2023
1 parent 1a22aab commit 1c87828
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 58 deletions.
43 changes: 1 addition & 42 deletions samples/output/output.prod.dynamo.drawio

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion samples/output/output.prod.iam-roles.drawio

This file was deleted.

Binary file added samples/output/output.prod.iam-roles.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/output/png/output.prod.dynamo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
213 changes: 198 additions & 15 deletions samples/samples/aws_dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,216 @@


def prepare_data_model(mcd):
# DynamoDB Table
table_name = "prod-dynamo-table"
dynamo_metadata = {
"Capacity mode": "PAY_PER_REQUEST",
"DeletionProtectionEnabled": False,
"ItemCount": 10000,
"Replicas": 0,
"TableSizeBytes": 99999
# DynamoDB Table definition based on AWS specification
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/describe_table.html
dynamo_table = {
'AttributeDefinitions': [
{
'AttributeName': 'first',
'AttributeType': 'S'
},
{
'AttributeName': 'second',
'AttributeType': 'N'
},
{
'AttributeName': 'third',
'AttributeType': 'B'
},
],
'TableName': 'prod-dynamo-table',
'KeySchema': [
{
'AttributeName': 'string',
'KeyType': 'HASH'
},
],
'TableSizeBytes': 123,
'ItemCount': 123,
'TableArn': 'arn:aws:dynamodb:eu-west-1:123456789:table/prod-dynamo-table',
'LocalSecondaryIndexes': [{
'IndexName': 'firstIndex',
'KeySchema': [
{
'AttributeName': 'string',
'KeyType': 'HASH'
},
],
'Projection': {
'ProjectionType': 'ALL'
},
'IndexSizeBytes': 777,
'ItemCount': 123,
},
{
'IndexName': 'secondIndex',
'KeySchema': [
{
'AttributeName': 'alternativeKey',
'KeyType': 'RANGE'
},
],
'Projection': {
'ProjectionType': 'ALL'
},
'IndexSizeBytes': 777,
'ItemCount': 123,
}

],
'GlobalSecondaryIndexes': [
{
'IndexName': 'string',
'KeySchema': [
{
'AttributeName': 'string',
'KeyType': 'HASH'
},
],
'Projection': {
'ProjectionType': 'ALL',
'NonKeyAttributes': [
'string',
]
},
'IndexSizeBytes': 123,
'ItemCount': 123,
'IndexStatus': 'ACTIVE',
'ProvisionedThroughput': {
'NumberOfDecreasesToday': 123,
'ReadCapacityUnits': 123,
'WriteCapacityUnits': 123
}
},
],
'StreamSpecification': {
'StreamEnabled': True,
'StreamViewType': 'NEW_IMAGE'
},
'LatestStreamLabel': "2023-04-14T08:29:21.074",
'LatestStreamArn': "arn:aws:dynamodb:eu-west-1:123456789:table/prod-dynamo-table/stream",
'Replicas': [
{
'RegionName': 'string',
'ReplicaStatus': 'ACTIVE',
'ReplicaStatusDescription': 'string',
'ReplicaStatusPercentProgress': 'string',
'KMSMasterKeyId': 'string',
'ProvisionedThroughputOverride': {
'ReadCapacityUnits': 123
},
'GlobalSecondaryIndexes': [
{
'IndexName': 'string',
'ProvisionedThroughputOverride': {
'ReadCapacityUnits': 123
}
},
],
'ReplicaTableClassSummary': {
'TableClass': 'STANDARD'
}
},
],
'RestoreSummary': {
'SourceBackupArn': 'string',
'SourceTableArn': 'string',
'RestoreInProgress': False
},
'SSEDescription': {
'Status': 'ENABLED',
'SSEType': 'KMS',
'KMSMasterKeyArn': 'string',
},
'DeletionProtectionEnabled': True
}

table_arn = dynamo_table['TableArn']
table_name = dynamo_table['TableName']
metadata = {
'DeletionProtectionEnabled': dynamo_table['DeletionProtectionEnabled'],
'ItemCount': dynamo_table['ItemCount'],
'TableSizeBytes': dynamo_table['TableSizeBytes']
}
table_arn = "arn:aws:dynamodb:eu-west-1:123456789:table/prod-dynamo-table"

mcd.add_vertex(id=table_arn, node_name=table_name, arn=table_arn, node_type='dynamo', metadata=dynamo_metadata)
mcd.add_vertex(id=table_arn, node_name=table_name, arn=table_arn, node_type='dynamo', metadata=metadata)

# DynamoDB Stream
stream_arn = "arn:aws:dynamodb:eu-west-1:123456789:table/prod-dynamo-table/stream"
stream_arn = dynamo_table['LatestStreamArn']
stream_metadata = {
"LatestStreamLabel": "2023-04-14T08:29:21.074",
"StreamViewType": "NEW_AND_OLD_IMAGES"
"LatestStreamLabel": dynamo_table['LatestStreamLabel'],
"StreamViewType": dynamo_table['StreamSpecification']['StreamViewType']
}
mcd.add_vertex(id=stream_arn, node_name="2023-14-12T08:29:21.074", arn=stream_arn, node_type='dynamo_stream', metadata=stream_metadata)
mcd.add_vertex(id=stream_arn, node_name=dynamo_table['LatestStreamLabel'], arn=stream_arn, node_type='dynamo_stream', metadata=stream_metadata)
mcd.add_link(f'dynamo:{table_arn}', f'dynamo_stream:{stream_arn}', action=['DynamoDBStream'])

# KeySchema
rows_keys = ['recordId : HASH']
rows_keys = []
for attribute in dynamo_table['KeySchema']:
rows_keys.append(attribute['AttributeName'] + ' : ' + attribute['KeyType'])
mcd.add_list(f'Schema:{table_name}', rows=rows_keys)
mcd.add_link(f'dynamo:{table_arn}', f'Schema:{table_name}:list', action=['Key Schema'])

# Attributes
rows = []
for attribute in dynamo_table['AttributeDefinitions']:
rows.append(attribute['AttributeName'] + ' : ' + attribute['AttributeType'])
mcd.add_list(table_name=f'Attributes:{table_name}', rows=rows)
mcd.add_link(src_node_id=f'dynamo:{table_arn}', dst_node_id=f'Attributes:{table_name}:list', action=['AttributeDefinitions'])

# Local Secondary Indexes
if 'LocalSecondaryIndexes' in dynamo_table:
attributes = []
for attribute in dynamo_table['LocalSecondaryIndexes']:
attributes.append('IndexName: ' + attribute['IndexName'])
mcd.add_list(f'LSIs:{table_name}', rows=attributes)
mcd.add_link(f'dynamo:{table_arn}', f'LSIs:{table_name}:list', action=['index: LSI'])

for attribute in dynamo_table['LocalSecondaryIndexes']:
attributes = []
index_name = attribute['IndexName']
attributes.append('IndexName: ' + index_name)
attributes.append('IndexSizeBytes: ' + str(attribute['IndexSizeBytes']))
attributes.append('ItemCount: ' + str(attribute['ItemCount']))
attributes.append('ProjectionType: ' + attribute['Projection']['ProjectionType'])

rows_schema = '{ '
for schema_attribute in attribute['KeySchema']:
rows_schema += (schema_attribute['AttributeName'] + ': ' + schema_attribute['KeyType'] + ',')
rows_schema = rows_schema.rstrip(rows_schema[-1]) + '}'
attributes.append('Schema: ' + rows_schema)

mcd.add_list(f'LSI:{table_name}-{index_name}', rows=attributes)
mcd.add_link(f'LSIs:{table_name}:list', f'LSI:{table_name}-{index_name}:list', action=[f'LSI : {index_name}'])

# Global Secondary Indexes
if 'GlobalSecondaryIndexes' in dynamo_table:
rows = []
for attribute in dynamo_table['GlobalSecondaryIndexes']:
rows.append('IndexName: ' + attribute['IndexName'])
mcd.add_list(f'GSIs:{table_name}', rows=rows)
mcd.add_link(f'dynamo:{table_arn}', f'GSIs:{table_name}:list', action=['index: GSI'])

for attribute in dynamo_table['GlobalSecondaryIndexes']:
rows = []
index_name = attribute['IndexName']
rows.append('IndexName: ' + index_name)
rows.append('IndexSizeBytes: ' + str(attribute['IndexSizeBytes']))
rows.append('IndexStatus: ' + attribute['IndexStatus'])
rows.append('ItemCount: ' + str(attribute['ItemCount']))
rows.append('RCU: ' + str(attribute['ProvisionedThroughput']['ReadCapacityUnits']))
rows.append('WCU: ' + str(attribute['ProvisionedThroughput']['WriteCapacityUnits']))
rows.append('ProjectionType: ' + attribute['Projection']['ProjectionType'])

rows_schema = '{ '
for schema_attribute in attribute['KeySchema']:
rows_schema += (schema_attribute['AttributeName'] + ': ' + schema_attribute['KeyType'] + ',')
rows_schema = rows_schema.rstrip(rows_schema[-1]) + '}'
rows.append('Schema: ' + rows_schema)

mcd.add_list(f'GSI:{table_name}-{index_name}', rows=rows)
mcd.add_link(f'GSIs:{table_name}:list', f'GSI:{table_name}-{index_name}:list', action=[f'GSI : {index_name}'])


def main():
prefix = 'prod'
Expand Down

0 comments on commit 1c87828

Please sign in to comment.