Carova

Serverless AWS VPC Create Custom VPC With Template

Configure and deploy a custom AWS VPC using your Serverless YAML template. The VPC can be reference in other AWS CloudFormation Stacks by automatically output variables.

Install the serverless-vpc-plugin:

1npm install serverless-vpc-plugin --save -D

Add the following to the custom section of your Serverless YAML file:

1plugins: 2 - serverless-vpc-plugin 3 4custom: 5 vpcConfig: 6 enabled: true 7 exportOutputs: true 8 cidrBlock: 10.13.0.0/16 9 createNatGateway: false 10 createNetworkAcl: false 11 createDbSubnet: true 12 createFlowLogs: false 13 createBastionHost: false 14 createNatInstance: false 15 createParameters: false 16 services: 17 - dynamodb 18 - s3 19 - secretsmanager 20 - sns 21 - timestream.query-cell2 22 - timestream.ingest-cell2 23 zones: 24 - us-east-1a 25 - us-east-1b

We've now created a custom AWS VPC in in the us-east region with VPC Endpoint Interfaces for 6 other AWS Services. VPC Endpoint Interfaces allow services in your VPC to interact with the specified resources:

  1. DynamoDB
  2. AWS S3
  3. AWS SecretsManager
  4. AWS SNS
  5. AWS TimeStream (Query)
  6. AWS TimeStream (Write)

You can deploy other AWS CloudFormation Stack services into the same VPC by adding the following to the other Stack's Serverless file:

1provider: 2 vpc: 3 securityGroupIds: 4 - ${cf:other-stack-name.AppSecurityGroupId} 5 subnetIds: 6 - ${cf:other-stack-name.AppSubnet1} 7 - ${cf:other-stack-name.AppSubnet2}