Serverless: VPC settings Cannot be assigned by variables

Created on 10 Feb 2017  ·  3Comments  ·  Source: serverless/serverless

When using variables in the VPC definition in serverless.yml such as:

vpc:
securityGroupIds:
- ${self:custom.prod_sg_a}
- ${self:custom.prod_sg_b}
subnetIds:
- ${self:custom.prod_subnet_a}
- ${self:custom.prod_subnet_b}

serverless throws the following error in deployment:

Serverless: Deployment failed!

Serverless Error ---------------------------------------

 An error occurred while provisioning your stack: LambdaFunction
 - Value of property SecurityGroupIds must be of type
 List of String.

Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues

Your Environment Information -----------------------------
OS: darwin
Node Version: 5.1.1
Serverless Version: 1.6.1

Should be able to use variables (including nested variables) to support deployment across different accounts and therefore different VPCs.

bug

Most helpful comment

EDIT: DISREGARD - I had copied this config from online somewhere and it pasted a hyphen instead of a dash, resulting in the error I saw.

I'm getting this same error. I only have one security group.

I've tried both

provider:
  name: aws
  runtime: nodejs6.10
  vpc:
    securityGroupIds:
      — "sg-abcdefg1"
    subnetIds:
      — "subnet-abcdefg1"
      — "subnet-abcdefg2"

AND

provider:
  name: aws
  runtime: nodejs6.10
  vpc:
    securityGroupIds: "sg-abcdefg1"
    subnetIds:
      — "subnet-abcdefg1"
      — "subnet-abcdefg2"

Is this just a yaml thing?

EDIT: DISREGARD - I had copied this config from online somewhere and it pasted a hyphen instead of a dash, resulting in the error I saw.

All 3 comments

I am using variables for this but its with 1.3. Do you have your exact serverless.yml file?

Below is an example of how I am doing this. It is modified so might not be exactly right but should give you a starting point.

custom:
  vpc:
    securityGroupIds: ${self:custom.SecurityGroupId}
    subnetIds: ${self:custom.SubnetId}
  SubnetId:
    - TBA
  SecurityGroupId:
    - TBA

functions:
  test:
    handler: handlers/test.handler
    vpc: ${self:custom.vpc}

Thanks! That seemed to do the trick. Must be setting the variable as a list rather than a list of variables. Or something like that. Appreciate the help!

EDIT: DISREGARD - I had copied this config from online somewhere and it pasted a hyphen instead of a dash, resulting in the error I saw.

I'm getting this same error. I only have one security group.

I've tried both

provider:
  name: aws
  runtime: nodejs6.10
  vpc:
    securityGroupIds:
      — "sg-abcdefg1"
    subnetIds:
      — "subnet-abcdefg1"
      — "subnet-abcdefg2"

AND

provider:
  name: aws
  runtime: nodejs6.10
  vpc:
    securityGroupIds: "sg-abcdefg1"
    subnetIds:
      — "subnet-abcdefg1"
      — "subnet-abcdefg2"

Is this just a yaml thing?

EDIT: DISREGARD - I had copied this config from online somewhere and it pasted a hyphen instead of a dash, resulting in the error I saw.

Was this page helpful?
0 / 5 - 0 ratings