一个建议,我用无服务器发送了 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