tschumann
tschumann

Reputation: 3246

make serverless.yml use existing vpc

Is it possible to get a serverless.yml template so substitute in a VPC id for a VPC that already exists in an AWS account?

Me and my colleagues each have our own AWS accounts that are provisioned by our company with a single VPC (and we don't have permission to create our own VPCs) so I want my serverless.yml to be able to, for each person, get the VPC id for that person's account and substitute it in to serverless.yml

Is there a way to do this or with serverless or will it be necessary to parametrise it with an environment variable?

Upvotes: 1

Views: 2687

Answers (2)

Eduardo Díaz
Eduardo Díaz

Reputation: 138

Edit your serverless.yml

Try to add the vpc on the functions or in the provider section:

In specific function:

 functions:
  getAllTrucksTSPFleetilla:
      handler: src/functions/get-all-trip-stop-parking.handler
      vpc:
        securityGroupIds:
          - sg-xxxxxxx1
          - sg-xxxxxxx2
        subnetIds:
          - subnet-xxxxxx1
          - subnet-xxxxxx2
          - subnet-xxxxxx3

In all project:

provider:
  name: aws
  vpc:
    securityGroupIds:
      - sg-xxxxxxx1
      - sg-xxxxxxx2
    subnet-xxxxxx1
      - subnet-xxxxxx2
      - subnet-xxxxxx3

To get the the security groups and the subnest you need to go to the VPC service on the aws console and find this information.

Visit the serverless documentation: sls vpc docs

Upvotes: 2

Mikelax
Mikelax

Reputation: 572

If the VPCs were created through Cloudformation templates, you can export a stack output value for each of your VPC Ids. Then within your serverless.yml file you can use the built-in intrinsic function Fn::ImportValue to read the value of the exported vpc id.

If you aren't using Cloudformation or can't export the vpc id, then I would suggest to add it as a parameter to serverless. I don't personally see harm in having a parameter for VPC ID.

Upvotes: 1

Related Questions