[英]Using serverless to add new lambda functions to same Gateway API?
I'm working on multiple functions that we will be using to manage images in an S3 bucket. 我正在处理多个功能,我们将使用这些功能来管理S3存储桶中的图像。 I'm trying to figure out how to user serverless to deploy the various node.js scripts to lambda and thus far have figured that part out. 我正在尝试弄清楚如何无用户地将各种node.js脚本部署到lambda,到目前为止,已经弄清楚了这一部分。 But I would like to deploy them all as different paths under the same gateway API. 但是我想将它们全部部署为同一网关API下的不同路径。 I tried adding 'apiName' under the provider section, but it just creates a new GatewayAPI with the same name as the first. 我尝试在提供者部分下添加“ apiName”,但它只是创建了一个与第一个相同名称的新GatewayAPI。
Sample serverless.yml: 示例serverless.yml:
service: GetObjectInfo
frameworkVersion: ">=1.1.0"
custom:
region: us-east-2
provider:
name: aws
runtime: nodejs8.10
region: ${self:custom.region}
stage: ${opt:stage, 'dev'}
apiName: myGatewayAPI
memorySize: 256
timeout: 2
role: arn:aws:iam::118934906513:role/lambda-s3-role
functions:
GetObjectInfo:
name: GetObjectInfo
handler: index.handler
events:
- http:
path: /GetObjectInfo
method: POST
cors: true
environment:
REGION: ${self:custom.region}
package:
exclude:
- package-lock.json
- test/**
- .idea/**
- .git/**
- node_modules
What do I do in a second/third/nth to get them to deploy the gateway part into the same gateway interface? 我要在第二/第三/第n次执行什么操作,以使他们将网关部件部署到同一网关接口中? I prefer to keep the lambda code in separate project/git folders for maintenance purposes. 我更喜欢将lambda代码保存在单独的project / git文件夹中,以进行维护。
I think the serverless framework creates all the functions under the same API Gateway by default. 我认为默认情况下,无服务器框架会在同一API网关下创建所有功能。
eg the following should work: 例如以下应该工作:
custom:
region: us-east-2
provider:
name: aws
runtime: nodejs8.10
region: ${self:custom.region}
stage: ${opt:stage, 'dev'}
memorySize: 256
timeout: 2
role: arn:aws:iam::118934906513:role/lambda-s3-role
functions:
GetObjectInfo:
name: GetObjectInfo
handler: index.handler
events:
- http:
path: /GetObjectInfo
method: POST
cors: true
environment:
REGION: ${self:custom.region}
PutObjectInfo:
name: PutObjectInfo
handler: index.handlerPut
events:
- http:
path: /PutObjectInfo
method: PUT
cors: true
environment:
REGION: ${self:custom.region}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.