Unset global property for specific function in serverless.yml

In serverless.yml, we can apply properties across all functions e.g. ‘vpc’ under ‘provider’ is applied to all functions in the service. How can we apply it to all functions except 1? That is, for the specific function set something like ‘vpc’: Null?

You can assign VPCs per function according to https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/. However, it doesn’t seem possible to negate a globally set VPC. It would be nice to be able to set vpc: false under a function and have that skip the VPC config.

What you want to accomplish is possible through custom variables. Move your VPC configuration under custom:

custom:
  vpc:
    securityGroupIds:
      - sg-XXXXXXXX
    subnetIds:
      - subnet-XXXXXXXX
      - subnet-XXXXXXXX
      - subnet-XXXXXXXX

Then add vpc with a reference to the custom variable to each function that you want to apply it to:

functions:
  myFunc:
    handler: handler.myHandler
    vpc: ${self:custom.vpc}

Hope that helps.

1 Like