如何通过EventBridge Scheduler带路径调用AWS Lambda函数?
解决方案
你的Nuxt3应用部署为Lambda函数时,依赖API Gateway格式的事件来识别请求路径。因此需要在EventBridge Scheduler的Input字段中构造对应格式的JSON,明确指定path参数。
修改后的CloudFormation模板Input部分如下:
LambdaScheduler: Type: AWS::Scheduler::Schedule Properties: FlexibleTimeWindow: MaximumWindowInMinutes: 5 Mode: FLEXIBLE Name: lambda-schedule ScheduleExpression: cron(0/15 * * * ? *) State: ENABLED Target: Arn: !GetAtt HogeLambdaFunction.Arn Input: |- { "requestContext": { "http": { "method": "GET" } }, "path": "/api/v1/hoge", "headers": {}, "body": null } RoleArn: !GetAtt SchedulerRole.Arn DeadLetterConfig: Arn: !GetAtt DeadLetterQueue.Arn
关键说明
- Nuxt3的Lambda适配器通过API Gateway事件结构解析请求路径、方法等信息,必须确保
Input中包含path字段。 - 若接口需要POST等其他请求方法,修改
requestContext.http.method的值即可。 - 如果需要传递请求体,将
body字段替换为对应的JSON字符串(注意格式转义)。
内容的提问来源于stack exchange,提问作者ahoo
相关产品推荐
相关产品推荐

