使用无服务器将新的lambda函数添加到相同的Gateway API吗?

问题描述 投票:0回答:1

我正在使用多种功能来管理S3存储桶中的图像。我试图弄清楚如何无用户地将各种node.js脚本部署到lambda,到目前为止,这一点已经解决了。但是我想将它们全部部署为同一网关API下的不同路径。我尝试在提供者部分下添加“ apiName”,但它只是创建一个与第一个相同名称的新GatewayAPI。

示例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

我在第二,第三,第三部分中如何使他们将网关部件部署到同一网关接口中?我倾向于将lambda代码保存在单独的project / git文件夹中,以进行维护。

amazon-web-services amazon-s3 aws-serverless amazon-gateway
1个回答
0
投票

我认为默认情况下,无服务器框架会在同一API网关下创建所有功能。

例如以下应该工作:

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}
© www.soinside.com 2019 - 2024. All rights reserved.