Aws lambda 无服务器:httpApi中的请求参数
这就是我的Aws lambda 无服务器:httpApi中的请求参数,aws-lambda,serverless,aws-http-api,Aws Lambda,Serverless,Aws Http Api,这就是我的serverless.yml部分的外观: my-function: - http: # <---- http method: POST path: /my-function/{id} request: parameters: paths: id:true 但我得到了这个错误信息: Serverless: Configuration warning at
serverless.yml
部分的外观:
my-function:
- http: # <---- http
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参数?一个建议,我用serverless发送了4天,只是为了意识到我需要先了解Lambda和整个体系结构。如果您对整个框架还不熟悉,我会暂时跳过无服务器框架,然后再回头看,因为它非常有用。好的,回答你的问题:
这是基本的httpApi格式:
functions:
params:
name: myLambdaName
handler: index.handler
events:
- httpApi:
path: /v1/test
method: get
这是你需要的东西
这就是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
服务:我的express应用程序
框架版本:“2”
供应商:
名称:aws
stackName:myName#为CloudFormation堆栈使用自定义名称
运行时:nodejs12.x
lambdahashing版本:20201221
stage:v1#您的默认stage,这里定义的一个lambda和所有服务都将使用
地区:us-east-1#非常感谢您的详细解释。但是,膝关节炎并没有回答我的问题:(我想知道如何用PARAMETES定义URL:像代码> /API/toDs/{ID}/Edg/<代码>……我切换到膝关节炎和KOA路由器作为我的服务器框架,用“代码>无服务器HTTP 将所有的东西包在单个lambda函数中。
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