postToConnection()引发错误“访问被拒绝。令牌丢失”

时间:2019-06-24 09:29:41

标签: node.js amazon-web-services websocket aws-sdk

我是AWS的新手,调试后,websocket出现问题,发现push lambda中出现身份验证错误。

push lambda如下:

module.exports.push = async (event, context) => {
try {

    let client = new Aws.ApiGatewayManagementApi({
        apiVersion: '2018-11-29',
        endpoint: process.env.ENDPOINT
    });
    let arr=[];

    //some loop
    arr.push(client.postToConnection({ ConnectionId: "connection id here", Data: JSON.stringify("data") }, (err, data) => {
            if (err) {
                console.log("pushing failed: ", err); <<-- error here: UnknownError: Access denied. Token is missing -->>
            }
            else {
                console.log("pushed to connection: ", data);
            }
        }).promise())

    //loop ends 

    try {           
        await Promise.all(arr)
    }
    catch (err) {
        return {
            statusCode: 400
        };
    }
    return {
        statusCode: 200
    };

}
catch (err) {
    return {
        statusCode: 400
    };
}
};

不知道出了什么问题。有人可以帮我吗?

0 个答案:

没有答案