here a code that i has write it in lambda to get data form url and insert parameter into dynamoDB
const AWS = require('aws-sdk');
const ddb = new AWS.DynamoDB.DocumentClient({region: 'ap-southeast-1'});
exports.handler = async (event, context, callback) => {
var obj = JSON.parse(JSON.stringify(event.queryStringParameters));
const requestId = context.awsRequestId;
await createMessage(requestId).then(() => {
callback(null, {
statusCode: 200,
body: `
<hl>query string parameters</hl>
<p>${JSON.stringify(event.queryStringParameters)}</p>
<p>one: ${obj.one}</p>
<hr/>
<hl>path</hl>
<p>${JSON.stringify(event.requestContext.http.path)}</p>
<hr/>
`,
headers: {
'Content-Type' : 'text/html; charset=uft-8',
}
});
}).catch((err) => {
console.error(err)
})
};
function createMessage(requestId) {
const params = {
TableName: 'Message',
Item: {
'messageId' : '321',
}
}
return ddb.put(params).promise();
}
here it's Response
{
"errorType": "SyntaxError",
"errorMessage": "Unexpected token u in JSON at position 0",
"trace": [
"SyntaxError: Unexpected token u in JSON at position 0",
" at JSON.parse (<anonymous>)",
" at Runtime.exports.handler (/var/task/index.js:5:20)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}
what should i do next to fix unexpected token u in JSON at position 0