【发布时间】:2019-12-06 16:47:56
【问题描述】:
我已经设置了一个 AWS API Gateway Web Socket API。
我的设置概述:客户端 --(升级请求)--> AWS API Gateway ----> Lambda 授权者
我的$connect路线:
请注意:
- 目前还没有
Integration Response和Route Response。有问题吗? -
connect-authorizer是我的 Lambda 授权者的名称
connect-authorizer确实收到了客户端的请求,但是没有给客户端授权!
下面是connect-authorizer的代码(参考here,Request-based函数):
exports.handler = function(event, context, callback) {
console.log("Received event", JSON.stringify(event, null, 2));
callback(null, generateAllow("me", event.methodArn)); // just authorize!
//callback("Unauthorized"); // if replaced by this line, my Terminal does receive error 401 !
};
const generatePolicy = function(principalId, effect, resource) {
console.log("generating policy", principalId, effect, resource)
const authResponse = {};
authResponse.principalId = principalId;
authResponse.context = {
"stringKey": "stringval",
"numberKey": 123,
"booleanKey": true
};
if (effect && resource) {
const statementOne = {};
statementOne.Action = "execute-api:Invoke";
statementOne.Effect = effect;
statementOne.Resource = resource;
const policyDocument = {};
policyDocument.Version = "2012-10-17";
policyDocument.Statement = [statementOne];
authResponse.policyDocument = policyDocument;
}
console.log("final authResponse", authResponse)
return authResponse;
};
const generateAllow = function(principalId, resource) {
return generatePolicy(principalId, "Allow", resource);
};
const generateDeny = function(principalId, resource) {
return generatePolicy(principalId, "Deny", resource);
};
但我总是从终端 wscat 收到错误 500:
登录CloudWatch:
Statement: [ [Object] ] 有问题吗?为什么我总是收到错误 500?
【问题讨论】:
标签: amazon-web-services websocket aws-lambda aws-api-gateway http-error