Skip to content

Insert Complex Data into Dynamo DB Table

0

Can I know how I can construct the following structure to insert into the Dynamo DB table please?

I have used data type map "M" for mainDescriptionList, imageList, eventList and coordinatorList but it throws a validation error.

Appreciate your help on this.

{
    'groupId': {'S': 'exirktzb-mddemfft-j03le7mm'}, 
    'groupName': {'S': 'adasda dasdsad'}, 
    'groupFriendlyName': {'S': 'adasda-dasdsad-'}, 
    'groupShortDescription': {'S': 'dasda adasdasd asdasda'}, 
    'createdDateTime': {'S': '2024-09-06 17:33:26.354815'}, 
    'updatedDateTime': {'S': ''}, 
    'mainDescriptionList': {
        [
            {   
                'descriptionTitle': {'S': 'sadasd sadasd'}, 
                'descriptionText': {'S': '<p>dasd asdadasd asdadaasdad sdsad</p>'}
            }, 
            {
                'descriptionTitle': {'S': 'sadasd sadasd'}, 
                'descriptionText': {'S': '<p>dasd asdadasd asdadaasdad sdsad</p>'}
            }
        ]
    }, 
    'imageList': {
        [
            {
                'imageTitle': {'S': 'sdad sdad'}, 
                'imageLink': {'S': 'https://tests3-bucket.s3.amazonaws.com/images/blackberries.png'}, 
                'imageFileName': {'S': 'blackberries.png'}, 
                'imageAlt': {'S': 'sdad sdad'}
            }, 
            {
                'imageTitle': {'S': 'sdad sdad sfsd'}, 
                'imageLink': {'S': 'https://tests3-bucket.s3.amazonaws.com/images/energy-drink.png'}, 
                'imageFileName': {'S': 'energy-drink.png'}, 
                'imageAlt': {'S': 'sdad sdad sfsd'}
            }
        ]
    }, 
    'eventList': {
        [
            {
                'eventTitle': {'S': 'asdasda sadsad'}, 
                'eventText': {'S': 'asdasd sadasdas dasdasdad'}
            }, 
            {
                'eventTitle': {'S': 'asdasda sadsad'}, 
                'eventText': {'S': 'asdasd sadasdas dasdasdad'}
            }
        ]
    }, 
    'coordinatorList': {
        [
            {
                'coordinatorName': {'S': 'asda'}, 
                'coordinatorImageLink': {'S': 'https://tests3-bucket.s3.amazonaws.com/coordinators/mango-juice.png'}, 
                'coordinatorImageAlt': {'S': 'asda'}, 
                'coordinatorImageName': {'S': 'mango-juice.png'}
            }, 
            {
                'coordinatorName': {'S': 'asdada'}, 
                'coordinatorImageLink': {'S': 'https://tests3-bucket.s3.amazonaws.com/coordinators/apples.png'}, 
                'coordinatorImageAlt': {'S': 'asdada'}, 
                'coordinatorImageName': {'S': 'apples.png'}
                }
        ]
    }
}

asked a year ago203 views
2 Answers
3
Accepted Answer

The issue is the LISTs and MAPs are not formatted correctly

Also, always use a " instead of '

{
    "groupId": {"S": "exirktzb-mddemfft-j03le7mm"},
    "groupName": {"S": "adasda dasdsad"},
    "groupFriendlyName": {"S": "adasda-dasdsad-"},
    "groupShortDescription": {"S": "dasda adasdasd asdasda"},
    "createdDateTime": {"S": "2024-09-06 17:33:26.354815"},
    "updatedDateTime": {"S": ""},
    "mainDescriptionList": {
        "L": [
            {
                "M": {
                    "descriptionTitle": {"S": "sadasd sadasd"},
                    "descriptionText": {"S": "<p>dasd asdadasd asdadaasdad sdsad</p>"}
                }
            },
            {
                "M": {
                    "descriptionTitle": {"S": "sadasd sadasd"},
                    "descriptionText": {"S": "<p>dasd asdadasd asdadaasdad sdsad</p>"}
                }
            }
        ]
    },
    "imageList": {
        "L": [
            {
                "M": {
                    "imageTitle": {"S": "sdad sdad"},
                    "imageLink": {"S": "https://tests3-bucket.s3.amazonaws.com/images/blackberries.png"},
                    "imageFileName": {"S": "blackberries.png"},
                    "imageAlt": {"S": "sdad sdad"}
                }
            },
            {
                "M": {
                    "imageTitle": {"S": "sdad sdad sfsd"},
                    "imageLink": {"S": "https://tests3-bucket.s3.amazonaws.com/images/energy-drink.png"},
                    "imageFileName": {"S": "energy-drink.png"},
                    "imageAlt": {"S": "sdad sdad sfsd"}
                }
            }
        ]
    },
    "eventList": {
        "L": [
            {
                "M": {
                    "eventTitle": {"S": "asdasda sadsad"},
                    "eventText": {"S": "asdasd sadasdas dasdasdad"}
                }
            },
            {
                "M": {
                    "eventTitle": {"S": "asdasda sadsad"},
                    "eventText": {"S": "asdasd sadasdas dasdasdad"}
                }
            }
        ]
    },
    "coordinatorList": {
        "L": [
            {
                "M": {
                    "coordinatorName": {"S": "asda"},
                    "coordinatorImageLink": {"S": "https://tests3-bucket.s3.amazonaws.com/coordinators/mango-juice.png"},
                    "coordinatorImageAlt": {"S": "asda"},
                    "coordinatorImageName": {"S": "mango-juice.png"}
                }
            },
            {
                "M": {
                    "coordinatorName": {"S": "asdada"},
                    "coordinatorImageLink": {"S": "https://tests3-bucket.s3.amazonaws.com/coordinators/apples.png"},
                    "coordinatorImageAlt": {"S": "asdada"},
                    "coordinatorImageName": {"S": "apples.png"}
                }
            }
        ]
    }
}

AWS
EXPERT
answered a year ago
EXPERT
reviewed a year ago
  • Thank you so much @Almas-AWS. I have constructed the data structure according what you have posted and I was able to save the item into Dynamo DB table. Thank you for providing the answer.

1

Not directly answering the question:

You haven't mentioned what language you're using. If you're using Python, consider using a DynamoDB Table client - the reason being is that it operates at a (slightly) higher level than the regular DynamoDB client. Using the Table construct you can just pass in dictionaries, lists, etc. and the client does the conversion for you on both reads and writes.

AWS
EXPERT
answered a year ago
EXPERT
reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.