DynamoDb Cannot read properties of undefined (reading ‘0’) when writing data

I am trying to write some data into DynamoDb. I’ve created the table with a partition key called s3jsonfile (String), and a sort key called messageId (String).

My main goal is to use this table to track the progress of my processing. Since my logic is based on receiving SQS messages, i’m gonna write there how many entries from the SQS message were processed, total number of entries, message number and the s3 key.

For writing, i’m passing to the function the s3jsonfile (partitionkey) and messageId(sort key).

I’ve verified the data i’m passing multiple times, its even included on my debugging. However, i’m always receiving this error:

Error initializing message processing: TypeError: Cannot read properties of undefined (reading '0')
    at Object.visit (/home/ec2-user/node-project/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:1003:36)
    at se_AttributeValue (/home/ec2-user/node-project/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:2544:25)
    at /home/ec2-user/node-project/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:2743:16
    at Array.reduce (<anonymous>)
    at se_ExpressionAttributeValueMap (/home/ec2-user/node-project/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:2739:32)
    at ExpressionAttributeValues (/home/ec2-user/node-project/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:3102:39)
    at applyInstruction (/home/ec2-user/node-project/node_modules/@smithy/smithy-client/dist-cjs/index.js:1092:27)
    at take (/home/ec2-user/node-project/node_modules/@smithy/smithy-client/dist-cjs/index.js:1060:5)
    at se_UpdateItemInput (/home/ec2-user/node-project/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:3096:40)
    at se_UpdateItemCommand (/home/ec2-user/node-project/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:1360:25)
Parameters used: {
  TableName: 'messageProcessingTable',
  Key: {
    s3jsonfile: 'converted_data_1726002816321.json',
    messageId: 'Message 1 of 1'
  },
  UpdateExpression: 'SET totalEntries = :totalEntries, entriesProcessed = :entriesProcessed, processingStatus =

:processingStatus, lastUpdated = :timestamp’,
ExpressionAttributeValues: {
‘:totalEntries’: ‘6’,
‘:entriesProcessed’: ‘0’,
‘:processingStatus’: ‘0’,
‘:timestamp’: ‘2024-09-10T21:13:45.990Z’
}
}

I’ve double checked my schema, my function to write the data, and i still can’t figure out the problem. Also, i’m using AWS SDK v3 so there is no need to pass S for string and N for number (thats why i’m passing to the update command the entire string).

The error is happening because i still have no data on this table?
The goal on this specific method is to initialize writing the data on this s3jsonfile (key) with the values i provided inside the method (sorting key).

I’m kinda new to DynamoDB. I don’t know if i should create my table in another way (without a sorting key maybe). Any input is highly appreciated, and sorry for the english.

Below is my code. Any additional information i’ll be glad to reply. If something on my post isn’t clear, please let me know. Thanks a lot.

// Initialize the message processing entry
const initializeProcessing = async (s3jsonfile, messageId, totalEntries, messageProcessingTableName) => {
    console.log('S3 Key:', s3jsonfile);
    console.log('Message Info:', messageId);
    console.log('Total Entries:', totalEntries);

    const params = {
        TableName: messageProcessingTableName,
        Key: {
            s3jsonfile,    // Partition key
            messageId      // Sort key
        },
        UpdateExpression: 'SET totalEntries = :totalEntries, entriesProcessed = :entriesProcessed, processingStatus = :processingStatus, lastUpdated = :timestamp',
        ExpressionAttributeValues: {
            ':totalEntries': totalEntries.toString(),  // Ensure this is a string
            ':entriesProcessed': '0',  // Plain string
            ':processingStatus': '0',  // Plain string
            ':timestamp': new Date().toISOString()  // ISO string for date
        }
    };

    console.log('Parameters for UpdateItemCommand:', JSON.stringify(params, null, 2)); // Detailed logging

    try {
        await dynamoDB.send(new UpdateItemCommand(params));
        console.log(`Message ${messageId} initialized for ${totalEntries} entries.`);
    } catch (error) {
        console.error('Error initializing message processing:', error);
        console.error('Parameters used:', params); // Log parameters for debugging
    }
};

EDIT: To clarify, on this method the entriesProcessed is static as 0 because it will be updated when the processing logic is done. Also, processing status will be updated only when all entries from the json are processed. Thats why their attributes are like static strings now.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật