0

I'm working on multiple functions that we will be using to manage images in an S3 bucket. 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. But I would like to deploy them all as different paths under the same gateway API. I tried adding 'apiName' under the provider section, but it just creates a new GatewayAPI with the same name as the first.

Sample 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? I prefer to keep the lambda code in separate project/git folders for maintenance purposes.

Scott
  • 7,983
  • 2
  • 26
  • 41

1 Answers1

0

I think the serverless framework creates all the functions under the same API Gateway by default.

e.g. 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}
Erez
  • 1,690
  • 8
  • 9
  • so they have to be in the same project/repository? I was hoping to keep the [code for the] different tools separate because each is doing different things. – Scott Sep 18 '19 at 15:36
  • e.g. I have one that will resize and image and return the url of the resized file. I have one that will run a binary across an image to get properties of the image mask. I have one that will just retrieve the object head so I can check the bytes, mtime and metadata. They are used in completely different places for completely different things. Being in the same api is fine, but the code for each is distinct. – Scott Sep 18 '19 at 15:39
  • Is [this](https://serverless.com/blog/api-gateway-multiple-services/) what you're looking for? It will create multiple API gateways but you can use a single domain to call them – Erez Sep 18 '19 at 20:33
  • another question - if I combine them together, not all of them need all of the files. Can I put different include/exclude blocks by function? – Scott Sep 18 '19 at 22:00
  • To package node functions individually you should use https://github.com/serverless-heaven/serverless-webpack – Erez Sep 19 '19 at 05:56
  • I figured out you were able to specify function specific parameters such as the memory size, timeout and include/exclude blocks. Now I'm wondering is there any syntax for serverless deploy to just update the one you are working upon? – Scott Sep 19 '19 at 21:47
  • You can run `serverless deploy function -f functionName` – Erez Sep 20 '19 at 04:25