这是我的serverless.yml部分的样子:
my-function:
- http: # <---- http
method: POST
path: /my-function/{id}
request:
parameters:
paths: id:true我想使用AWS HTTP-API。因此,我将http ->改为httpApi,如下所示:
my-function:
- httpApi: # <---- now httpApi
method: POST
path: /my-function/{id}
request:
parameters:
paths: id:true但是我得到了这个错误信息:
Serverless: Configuration warning at 'functions['my-function'].events[2].httpApi': unrecognized property 'request'如何在httpApi节中定义URL参数?
发布于 2021-01-24 09:55:44
其中一个建议是,我使用serverless 4天后才意识到,我需要首先了解Lambda和整个架构。如果你对整个事情都是新手,我会先跳过无服务器框架,然后再回头看看,因为它非常有用。可以回答您的问题:
这是基本的httpApi格式:
functions:
params:
name: myLambdaName
handler: index.handler
events:
- httpApi:
path: /v1/test
method: get这是你需要的official documentation。
这是serverless.yml文件中所有内容的样子,我添加了一些注释,以便您了解发生了什么:
service: my-express-application
frameworkVersion: "2"
provider:
name: aws
stackName: myName # Use a custom name for the CloudFormation stack
runtime: nodejs12.x
lambdaHashingVersion: 20201221
stage: v1 # your default stage, the one lambda and all services define here will use
region: us-east-1 # <- This is your regeion, make sure it is or change it
httpApi: # rdefining your existing api gateway
# id: xxx # id of externally created HTTP API to which endpoints should be attached. This will allow you to use it but this lambda can't modify it
payload: "2.0" # the latest payload version by aws is 2.0
name: "v1-my-service" # Use custom name for the API Gateway API, default is ${opt:stage, self:provider.stage, 'dev'}-${self:service} you will only be able to modify it if you created the api using this stack and not referencing it above
cors: false # Implies default behavior, can be fine tuned with specficic options
timeout: 10
logRetentionInDays: 7 # Set the default RetentionInDays for a CloudWatch LogGroup
functions:
params:
name: myLambdaName
handler: index.handler
events:
- httpApi:
path: /v1/test
method: get发布于 2021-07-08 00:59:01
我不知道是不是太晚了,但这就是答案
handler: bin/function events: - httpApi: path: /function/{id} method: post
代码中的
id:= request.PathParameters["id"]
https://stackoverflow.com/questions/64701242
复制相似问题