APIGateway,Lambda,NestJSURLNotFound
创始人
2024-09-07 16:00:20
0

为API Gateway和Lambda集成NestJS服务时,访问URL返回404 Not Found错误的解决办法是在API Gateway的集成请求中配置正确的HTTP方法和资源路径。

具体代码示例:

  1. 在NestJS中定义API路由:

@Controller('example') export class ExampleController { constructor(private readonly exampleService: ExampleService) {}

@Get() async findAll(): Promise { return this.exampleService.findAll(); } }

  1. 在AWS Lambda中构建和导出NestJS应用程序:

import * as express from 'express'; import { NestFactory } from '@nestjs/core'; import { ExpressAdapter } from '@nestjs/platform-express'; import { ExampleModule } from './example.module'; import { Server } from 'http';

const server = express();

async function bootstrap(): Promise { const app = await NestFactory.create( ExampleModule, new ExpressAdapter(server), ); await app.init(); return server.listen(3000); }

export const handler = async (event, context) => { const server = await bootstrap(); const result = await serverlessExpress({ app: server, })(event, context); return result; };

  1. 在API Gateway中创建API并为Lambda函数添加一个触发器:
  • 方法:GET
  • 路径:/example
  • 绑定的Lambda函数:handler
  1. 在集成请求中将API Gateway的路径参数映射到Lambda的事件对象中:
  • 请求路径:/example
  • 接入协议:HTTP
  • HTTP方法:GET
  • 集成类型:Lambda函数
  • Lambda集成:Lambda函数的ARN
  • 集成请求的请求参数:
    • 查询字符串参数:映射方法为“passthrough”
  1. 部署API并测试请求URL是否返回正确的响应。

相关内容

热门资讯

终于知道(we poker)外... 终于知道(we poker)外挂透明挂辅助器(智能ai代打)的确真的有挂(2025已更新)(抖音)1...
必备辅助推荐(pokermas... 必备辅助推荐(pokermaster)外挂透明挂辅助app(透视辅助)都是真的有挂(2025已更新)...
重大科普(aapoker)外挂... 重大科普(aapoker)外挂透明挂辅助机制(透视辅助)本来真的有挂(2021已更新)(头条)1、重...
总算明白(智星德州)外挂透明挂... 总算明白(智星德州)外挂透明挂辅助器(透视)一贯真的有挂(2023已更新)(知乎);1、实时开挂更新...
最新技巧(wepOke)外挂透... 最新技巧(wepOke)外挂透明挂辅助app(辅助挂)都是真的有挂(2022已更新)(今日头条)1、...
每日必看教程(epoker)外... 每日必看教程(epoker)外挂透明挂辅助机制(辅助挂)一直真的有挂(2025已更新)(微博热搜);...
每日必看推荐(聚星扑克德州)外... 每日必看推荐(聚星扑克德州)外挂透明挂辅助脚本(透视辅助)就是真的有挂(2022已更新)(哔哩哔哩)...
盘点几款(约局吧)外挂透明挂辅... 盘点几款(约局吧)外挂透明挂辅助插件(透视辅助)的确真的有挂(2021已更新)(哔哩哔哩)1、玩家可...
实测揭晓(线上wpk德州)外挂... 实测揭晓(线上wpk德州)外挂透明挂辅助工具(智能ai代打)都是真的有挂(2024已更新)(百度)一...
教程攻略(来玩app)外挂透明... 教程攻略(来玩app)外挂透明挂辅助器(透视)一般真的有挂(2023已更新)(知乎)1、全新机制【软...