I have been trying to add a feature to a website that allows users to input an icalender link and will display it on the website. I found that the feature works when I input the link manually into DynamoDB. However the when I invoke the lambda function to add the link to the DB it throws this error and the DynamoDB never updates:
TypeError: Cannot read properties of undefined (reading '0'),
at e.visit (/var/task/calendar/put_ical.js:255:30795),
at serializeAws_json1_0AttributeValue (/var/task/calendar/put_ical.js:255:150114),
at /var/task/calendar/put_ical.js:255:174402,
at Array.reduce (<anonymous>),
at serializeAws_json1_0MapAttributeValue (/var/task/calendar/put_ical.js:255:174313),
at Object.M (/var/task/calendar/put_ical.js:255:150291),
at e.visit (/var/task/calendar/put_ical.js:255:30690),
at serializeAws_json1_0AttributeValue (/var/task/calendar/put_ical.js:255:150114),
at /var/task/calendar/put_ical.js:255:171557,
at Array.map (<anonymous>)
Here is the snippet of code I believe is throwing this error:
export const main = async (event) => {
try {
//Parse parameters and create ical id
const id = randomUUID();
const {skill_id, url} = JSON.parse(event.body);
//Update DynamoDB with new ical
const update = {
TableName: "Skill_Info",
Key: { skill_id: { S: skill_id } },
UpdateExpression: "SET ical = list_append(:i)",
ExpressionAttributeValues: {
":i": { M: { id: { S: id }, url: { S: url } } }
},
};
await updateDynamoItem(update);
And here is the way the function is getting invoked:
return useMutation({
mutationFn: (params) =>
API.post("api", "put_ical", {
body: {
skill_id: userData.skill_id,
url: params.url
},
}),
The ical attribute in the DB starts as a empty list and never gets updated. I honestly have no I idea why this is happening.