【发布时间】:2019-08-09 01:57:05
【问题描述】:
我正在尝试创建一个 API 网关,它将采用 AWS 中的任何方法。一旦调用了 API,lambda 函数就会解析出发送的消息,并决定从那里做什么。所以,给定一个 API Gateway 方法:
Type: AWS::ApiGateway::Method
Properties:
RestApiId: !Ref myRestApi
ResourceId: !Ref myResource
HttpMethod: ANY
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: POST
Uri:
Fn::Join:
- ''
- - 'arn:aws:apigateway:'
- Ref: AWS::Region
- :lambda:path/2015-04-30/functions/
- Fn::GetAtt:
- myLambdaFunction
- Arn
- /invocations
它会成功调用myLambdaFunction,那么我如何在node get 中获取实际发送HttpMethod 的lambda 函数?
例如:
exports.handler = (event, context, callback) => {
const response = {
statusCode: 200,
headers: {
"x-custom-header" : "This exists for reasons."
}
};
// I know that event doesn't actually have any httpmethod, but I'm not sure what it does have, or how to use it.
switch(event.httpmethod) {
case "POST":
console.log("POST!!!");
create(event, context, callback);
break;
case "GET":
console.log("GET!!!");
read(event, context, callback);
break;
case "PUT":
console.log("PUT!!!");
update(event, context, callback);
break;
}
上面的 lambda 应该能够 console.log 它得到的任何方法,但我不确定应该用什么来代替我刚刚编造的 event.httpmethod。
【问题讨论】:
标签: node.js amazon-web-services aws-lambda aws-api-gateway