简体   繁体   English

是否可以将 API 网关与 AWS lambda 中的节点路由连接?

[英]Is it possible to connect API gateway with node routes in AWS lambda?

I have implemented node application with AWSServerlessExpress and deployed in Lambda function.我已经使用 AWSServerlessExpress 实现了节点应用程序并部署在 Lambda 函数中。 but unable to point API Gateway to node routes.但无法将 API Gateway 指向节点路由。 every time I'm getting 404 status.每次我获得 404 状态时。

var express = require('express')
, router = express.Router()

router.post('/es', function(request, response){
    response.status(200).send("Lambda is triggered");
    response.end()
})

router.get('/es/csv', function(request, response){
    response.status(200).send("hello");
    response.end()
})

module.exports = router;

How can I point API gateway directly to get Or Post route?如何直接指向 API 网关以获取或发布路由?

After gone through the AWS documentation I have found a solution to my question.在浏览了 AWS 文档后,我找到了我的问题的解决方案。 To forward the request from API Gateway to node routes in lambda we have to create a new proxy ({proxy+})resource in API gateway under this resource create any method(based on your requirement).要将请求从 API 网关转发到 lambda 中的节点路由,我们必须在此资源下的 API 网关中创建一个新的代理 ({proxy+}) 资源创建任何方法(根据您的要求)。

在此处输入图片说明

I found this answer here: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-create-api-as-simple-proxy我在这里找到了这个答案: https : //docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-create-api-as-simple-proxy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM