我已经设置了一个AWS API Gateway Web套接字API。
我的设置概述:客户端-(升级请求)-> AWS API Gateway ----> Lambda Authorizer
我的$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?
答案 0 :(得分:0)
您是否尝试过添加集成响应?我相信$connect
路由应返回一个statusCode
属性设置为200的对象。
我记得this answer在设置过程中遇到困难时为我提供了帮助。