Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
Inserting a map item into DynamoDb

I have a table which is indexed by player accounts, and each player account has an empty map called "games." Whenever a new game is created, I'd like to insert a new item into that map for the new game, with some starting values. However this Javascript code below gives me an error:

            let newGame = {
                "live": { "BOOL": true },
                "result": { "S": "in_progress" }
            };

            let params = {
                TableName: "games_roster",
                Key: { "account_id" : playerAccount },
                UpdateExpression: "SET games.#game_id = :new_game",
                ExpressionAttributeNames: {
                    "#game_id": {"S": gameId}
                },
                ExpressionAttributeValues: {
                    ":new_game": {"M": newGame}
                }
            };

            await dynamoClient.send(new UpdateItemCommand(params));

The error:

TypeError: Cannot read properties of undefined (reading '0')
    at Object.AttributeValue.visit (models_0.js?31ed:996:1)
    at serializeAws_json1_0AttributeValue (Aws_json1_0.js?1450:4056:1)
    at eval (Aws_json1_0.js?1450:4484:1)
    at Array.reduce (<anonymous>)
    at serializeAws_json1_0Key (Aws_json1_0.js?1450:4478:1)
    at serializeAws_json1_0UpdateItemInput (Aws_json1_0.js?1450:5112:1)
    at eval (Aws_json1_0.js?1450:520:1)
    at step (tslib.es6.js?9ab4:102:1)
    at Object.eval [as next] (tslib.es6.js?9ab4:83:1)
    at eval (tslib.es6.js?9ab4:76:1)

I've verified that none of the variables are undefined by logging out the params object, so where would I be getting an TypeError?

Owing to @fedanov's answer, this is the correct format:

            let newGame = {
                live: { BOOL: true },
                result: { S: "in_progress" }
            };

            let params = {
                TableName: "games_roster",
                Key: { "account_id" : { S: playerAccount } },
                UpdateExpression: "SET games.#game_id = :new_game",
                ExpressionAttributeNames: {
                    "#game_id": gameId
                },
                ExpressionAttributeValues: {
                    ":new_game": { M: newGame }
                }
            };

            await dynamoClient.send(new UpdateItemCommand(params));
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are passing the wrong types to UpdateItemCommandInput. The Key parameter expects DynamoDB JSON values, ExpressionAttributeNames string values:

Key: { account_id: { S: playerAccount} },
ExpressionAttributeNames: { "#game_id" : gameId }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!