AWS DynamoDB Console Url#

This feature can print the AWS DynamoDB console url for the table, items. You can use this in you logging to quickly jump to the console to debug.

[1]:
# This example is about a table doesn't have range key
from rich import print as rprint
from datetime import datetime, timezone
import pynamodb_mate.api as pm

class Model1(pm.Model):
    class Meta:
        table_name = f"pynamodb-mate-example-console-model1"
        region = "us-east-1"
        billing_mode = pm.constants.PAY_PER_REQUEST_BILLING_MODE

    hash_key = pm.UnicodeAttribute(hash_key=True)
    data = pm.JSONAttribute(default=lambda: dict())

model1 = Model1(hash_key="a")

rprint(f"table overview: {Model1.get_table_overview_console_url()}")
rprint(f"view items in table: {Model1.get_table_items_console_url()}")
rprint(f"view item details: {model1.item_detail_console_url}")
table overview:
https://us-east-1.console.aws.amazon.com/dynamodbv2/home?region=us-east-1#table?initialTagKey=&name=pynamodb-mate-e
xample-console-model1&tab=overview
view items in table:
https://us-east-1.console.aws.amazon.com/dynamodbv2/home?region=us-east-1#item-explorer?initialTagKey=&maximize=tru
e&table=pynamodb-mate-example-console-model1
view item details:
https://us-east-1.console.aws.amazon.com/dynamodbv2/home?region=us-east-1#edit-item?table=pynamodb-mate-example-con
sole-model1&itemMode=2&pk=a&sk&ref=%23item-explorer%3Ftable%3Dpynamodb-mate-example-console-model1&route=ROUTE_ITEM
_EXPLORER
[2]:
# This example is about a table has both hash key and range key
class Model2(pm.Model):
    class Meta:
        table_name = f"pynamodb-mate-example-console-model2"
        region = "us-east-1"
        billing_mode = pm.constants.PAY_PER_REQUEST_BILLING_MODE

    hash_key = pm.UnicodeAttribute(hash_key=True)
    range_key = pm.UTCDateTimeAttribute(range_key=True)
    data = pm.JSONAttribute(default=lambda: dict())

model2 = Model2(
    hash_key="a",
    range_key=datetime(2000, 1, 1, tzinfo=timezone.utc),
)

rprint(f"table overview: {Model2.get_table_overview_console_url()}")
rprint(f"view items in table: {Model2.get_table_items_console_url()}")
rprint(f"view item details: {model2.item_detail_console_url}")
table overview:
https://us-east-1.console.aws.amazon.com/dynamodbv2/home?region=us-east-1#table?initialTagKey=&name=pynamodb-mate-e
xample-console-model2&tab=overview
view items in table:
https://us-east-1.console.aws.amazon.com/dynamodbv2/home?region=us-east-1#item-explorer?initialTagKey=&maximize=tru
e&table=pynamodb-mate-example-console-model2
view item details:
https://us-east-1.console.aws.amazon.com/dynamodbv2/home?region=us-east-1#edit-item?table=pynamodb-mate-example-con
sole-model2&itemMode=2&pk=a&sk=2000-01-01T00:00:00.000000+0000&ref=%23item-explorer%3Ftable%3Dpynamodb-mate-example
-console-model2&route=ROUTE_ITEM_EXPLORER
[ ]: