Frank
Frank

Reputation: 489

How to specify multiple subnets for Lambdas using serverless framework

I'm trying to use the example code to specify that my Lambda be available in multiple subnets:

provider:
  vpc: # Optional VPC. But if you use VPC then both subproperties (securityGroupIds and subnetIds) are required
    securityGroupIds:
      - securityGroupId1
      - securityGroupId2
    subnetIds:
      - subnetId1
      - subnetId2

However, I've tried several variations on this, with several different errors, and I can only ever get it to work with a single subnet specified.

provider:
  name:       aws
  runtime:    python3.8
  memorySize: 512
  lambdaHashingVersion: '20201221'
  stage: dev
  vpc:
    securityGroupIds:
    - sg-06e65a1f67c7XXXX
    subnetIds:
      - subnet-e84fXXXX
      – subnet-6e2cXXXX

Cannot parse "serverless.yml": bad indentation of a mapping entry in "$FOLDER/serverless.yml" (45:7)

Another attempt, with just a change in indentation:

provider:
  name:       aws
  runtime:    python3.8
  memorySize: 512
  lambdaHashingVersion: '20201221'
  stage: dev
  vpc:
    securityGroupIds:
    - sg-06e65a1f67c7XXXX
    subnetIds:
    - subnet-e84fXXXX
    – subnet-6e2cXXXX

Cannot parse "serverless.yml": can not read an implicit mapping pair; a colon is missed in "$FOLDER/serverless.yml" (45:22)

I also tried variations with indenting the securityGroupIds two spaces, with the same results. Any ideas appreciated. My thought is that this seems like a bug in the serverless framework, like it's expecting key pairs rather than a list?

Upvotes: 0

Views: 779

Answers (1)

LRutten
LRutten

Reputation: 1902

In the subnets section the second - is not a -. It's a different character. Try to delete it and replace it with an normal hyphen.

The error occurs because it can't parse the file as valid yaml due to that character.

Upvotes: 1

Related Questions