I'm playing with Dynamose library approach and generate automatically the database table with the current schema, but the I cannot get the DynamoDB data model to create in AWS, I verified the visualizer, the table is not there, I want to know if is possible to get the data model or only defining when is connected.
This is the schema:
import { Schema } from 'dynamoose';
export const NotificationSchema = new Schema({
id: {
type: String,
hashKey: true,
},
targetId: {
type: String,
index: {
type: 'global',
rangeKey: 'status',
},
},
userId: {
type: String,
index: {
type: 'global',
rangeKey: 'status',
},
},
content: {
type: String,
},
status: {
type: String,
},
createAt: {
type: String,
},
});
This is the metada in the workbench:
But the metadata is not showing the content attribute.
{
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
},
{
"AttributeName": "targetId",
"AttributeType": "S"
},
{
"AttributeName": "userId",
"AttributeType": "S"
},
{
"AttributeName": "status",
"AttributeType": "S"
}
],
"TableName": "aws-nestjs-starter-dev-notification-table",
"KeySchema": [
{
"AttributeName": "id",
"KeyType": "HASH"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": {},
"ProvisionedThroughput": {
"LastIncreaseDateTime": {},
"LastDecreaseDateTime": {},
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"TableSizeBytes": 381,
"ItemCount": 4,
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/aws-nestjs-starter-dev-notification-table",
"GlobalSecondaryIndexes": [
{
"IndexName": "targetIdGlobalIndex",
"KeySchema": [
{
"AttributeName": "targetId",
"KeyType": "HASH"
},
{
"AttributeName": "status",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"IndexStatus": "ACTIVE",
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"IndexSizeBytes": 378,
"ItemCount": 3,
"IndexArn": "arn:aws:dynamodb:ddblocal:000000000000:table/aws-nestjs-starter-dev-notification-table/index/targetIdGlobalIndex"
},
{
"IndexName": "userIdGlobalIndex",
"KeySchema": [
{
"AttributeName": "userId",
"KeyType": "HASH"
},
{
"AttributeName": "status",
"KeyType": "RANGE"
}
],
"Projection": {
"ProjectionType": "ALL"
},
"IndexStatus": "ACTIVE",
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"IndexSizeBytes": 378,
"ItemCount": 3,
"IndexArn": "arn:aws:dynamodb:ddblocal:000000000000:table/aws-nestjs-starter-dev-notification-table/index/userIdGlobalIndex"
}
]
}
I need to verify this table on the visualizer or get the json export, I created a Music table with commands and is possible to see in visualizer, I want this format:
{
"ModelName": "Music Library Data Model",
"ModelMetadata": {
"Author": "Amazon Web Services, Inc.",
"DateCreated": "Sep 05, 2019, 11:50 AM",
"DateLastModified": "Jun 30, 2023, 02:19 AM",
"Description": "This data model represents an Amazon DynamoDB schema for a music library application ",
"Version": "3.0",
"AWSService": "Amazon DynamoDB"
},
"DataModel": [
{
"TableName": "Songs",
"KeyAttributes": {
"PartitionKey": {
"AttributeName": "Id",
"AttributeType": "S"
},
"SortKey": {
"AttributeName": "Metadata",
"AttributeType": "S"
}
},
"NonKeyAttributes": [
{
"AttributeName": "DownloadMonth",
"AttributeType": "S"
},
{
"AttributeName": "TotalDownloadsInMonth",
"AttributeType": "S"
},
{
"AttributeName": "Title",
"AttributeType": "S"
},
{
"AttributeName": "Artist",
"AttributeType": "S"
},
{
"AttributeName": "TotalDownloads",
"AttributeType": "S"
},
{
"AttributeName": "DownloadTimestamp",
"AttributeType": "S"
}
],
"TableFacets": [
{
"FacetName": "SongDetails",
"KeyAttributeAlias": {
"PartitionKeyAlias": "SongId",
"SortKeyAlias": "Metadata"
},
"NonKeyAttributes": [
"Title",
"Artist",
"TotalDownloads"
],
"TableData": [
{
"Id": {
"S": "1"
},
"Metadata": {
"S": "Details"
},
"Title": {
"S": "Wild Love"
},
"Artist": {
"S": "Argyboots"
},
"TotalDownloads": {
"S": "3"
}
},
{
"Id": {
"S": "2"
},
"Metadata": {
"S": "Details"
},
"Title": {
"S": "Example Song Title"
},
"Artist": {
"S": "Jorge Souza"
},
"TotalDownloads": {
"S": "4"
}
}
],
"DataAccess": {
"MySql": {}
}
},
{
"FacetName": "Downloads",
"KeyAttributeAlias": {
"PartitionKeyAlias": "SongId",
"SortKeyAlias": "Metadata"
},
"NonKeyAttributes": [
"DownloadTimestamp"
],
"TableData": [
{
"Id": {
"S": "1"
},
"Metadata": {
"S": "Dld-9349823681"
},
"DownloadTimestamp": {
"S": "2018-01-01T00:00:07"
}
},
{
"Id": {
"S": "1"
},
"Metadata": {
"S": "Dld-9349823682"
},
"DownloadTimestamp": {
"S": "2018-01-01T00:01:08"
}
},
{
"Id": {
"S": "1"
},
"Metadata": {
"S": "Dld-9349823683"
},
"DownloadTimestamp": {
"S": "2018-01-01T00:20:10"
}
},
{
"Id": {
"S": "2"
},
"Metadata": {
"S": "Dld-9349823684"
},
"DownloadTimestamp": {
"S": "2018-01-02T00:00:00"
}
},
{
"Id": {
"S": "2"
},
"Metadata": {
"S": "Dld-9349823685"
},
"DownloadTimestamp": {
"S": "2018-01-03T00:00:02"
}
},
{
"Id": {
"S": "2"
},
"Metadata": {
"S": "Dld-9349836234"
},
"DownloadTimestamp": {
"S": "2018-01-04T01:00:03"
}
},
{
"Id": {
"S": "2"
},
"Metadata": {
"S": "Dld-9349823686"
},
"DownloadTimestamp": {
"S": "2018-01-05T01:10:03"
}
}
],
"DataAccess": {
"MySql": {}
}
}
],
"LocalSecondaryIndexes": [],
"GlobalSecondaryIndexes": [
{
"IndexName": "DownloadsByMonth",
"KeyAttributes": {
"PartitionKey": {
"AttributeName": "DownloadMonth",
"AttributeType": "S"
},
"SortKey": {
"AttributeName": "TotalDownloadsInMonth",
"AttributeType": "S"
}
},
"Projection": {
"ProjectionType": "ALL"
}
}
],
"TableData": [
{
"Id": {
"S": "1"
},
"Metadata": {
"S": "Month-01-2018"
},
"DownloadMonth": {
"S": "01-2018"
},
"TotalDownloadsInMonth": {
"S": "3"
}
},
{
"Id": {
"S": "2"
},
"Metadata": {
"S": "Month-01-2018"
},
"DownloadMonth": {
"S": "01-2018"
},
"TotalDownloadsInMonth": {
"S": "4"
}
}
],
"DataAccess": {
"MySql": {}
},
"BillingMode": "PROVISIONED",
"ProvisionedCapacitySettings": {
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"AutoScalingRead": {
"ScalableTargetRequest": {
"MinCapacity": 1,
"MaxCapacity": 10,
"ServiceRole": "AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
},
"ScalingPolicyConfiguration": {
"TargetValue": 70
}
},
"AutoScalingWrite": {
"ScalableTargetRequest": {
"MinCapacity": 1,
"MaxCapacity": 10,
"ServiceRole": "AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
},
"ScalingPolicyConfiguration": {
"TargetValue": 70
}
}
}
}
]
}
Using the follow command I am getting this:
λ aws dynamodb describe-table --table-name aws-nestjs-starter-dev-notification-table --endpoint-url http://localhost:8000
{
"Table": {
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
},
{
"AttributeName": "targetId",
"AttributeType": "S"
},
{
"AttributeName": "userId",
"AttributeType": "S"
},
{
"AttributeName": "status",
"AttributeType": "S"
}
],
"TableName": "aws-nestjs-starter-dev-notification-table",
"KeySchema": [
{
"AttributeName": "id",
"KeyType": "HASH"
}
],
The content attribute is missing.
Dynamoose stores an entire schema and it uses schema to object mapping. DynamoDB is a serverless service and disregards non-key attributes.
Your biggest concern is the
contentis not part of your official DynamoDB schema and that's for this reason, it's a non-key attribute.