我遇到了一个错误:无法读取未定义的属性'username',而且const用户名会说它未被使用。
完全错误:
Response:
{
"errorType": "TypeError",
"errorMessage": "Cannot read property 'username' of undefined",
"trace": [
"TypeError: Cannot read property 'username' of undefined",
" at Runtime.exports.handler (/var/task/index.js:7:50)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}
代码:
exports.handler = (event, context, callback) => {
console.log(event);
const connectionId = event.requestContext.connectionId;
const username = event.queryStringParameters.username;
addConnectionId(connectionId).then(() => {
callback(null, {
statusCode: 200,
});
});};
function addConnectionId(connectionId) {
const params = {
TableName: 'Chat',
Item: {
'connection_id' : connectionId,
'username' : username
}
};
return ddb.put(params).promise();
}
答案 0 :(得分:1)
您需要启用Use Lambda Proxy integration
才能访问查询参数。