JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4066
  • Score
    100M100P100Q125213F
  • License MIT

Serverless Plugin to generate a VPC

Package Exports

  • serverless-vpc-plugin

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (serverless-vpc-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

serverless-vpc-plugin

serverless npm version MIT licensed npm downloads

Automatically creates an AWS Virtual Private Cloud (VPC) using all available Availability Zones (AZ) in a region.

This plugin provisions the following resources:

  • AWS::EC2::VPC
  • AWS::EC2::InternetGateway (for outbound internet access)
  • AWS::EC2::VPCGatewayAttachment (to attach the InternetGateway to the VPC)
  • AWS::EC2::SecurityGroup (to execute Lambda functions [LambdaExecutionSecurityGroup])

If the VPC is allocated a /16 subnet, each availability zone within the region will be allocated a /20 subnet. Within each availability zone, this plugin will further divide the subnets:

  • AWS::EC2::Subnet "Application" (/21) - default route is either InternetGateway or NatGateway
  • AWS::EC2::Subnet "Public" (/22) - default route set InternetGateway
  • AWS::EC2::Subnet "Database" (/22) - no default route set in routing table

The subnetting layout was heavily inspired by the now shutdown Skyliner platform. 😞

Optionally, this plugin can also create AWS::EC2::NatGateway instances in each availability zone which requires provisioning AWS::EC2::EIP resources (AWS limits you to 5 per VPC, so if you want to provision your VPC across all 6 us-east availability zones, you'll need to request an VPC EIP limit increase from AWS).

Any Lambda functions executing with the "Application" subnet will only be able to access:

  • S3 (via an S3 VPC endpoint)
  • DynamoDB (via an DynamoDB VPC endpoint)
  • RDS instances (provisioned within the "DB" subnet)
  • ElastiCache instances (provisioned within the "DB" subnet)
  • RedShift (provisioned within the "DB" subnet),
  • DAX clusters (provisioned within the "DB" subnet)
  • Neptune clusters (provisioned with the "DB" subnet)

If your Lambda functions need to access the internet, then you MUST provision NatGateway resources.

By default, AWS::EC2::VPCEndpoint "Gateway" endpoints for S3 and DynamoDB will be provisioned within each availability zone to provide internal access to these services (there is no additional charge for using Gateway Type VPC endpoints). You can selectively control which AWS::EC2::VPCEndpoint "Interface" endpoints are available within your VPC using the services configuration option below. Not all AWS services are available in every region, so the plugin will query AWS to validate the services you have selected and notify you if any changes are required (there is an additional charge for using Interface Type VPC endpoints).

If you specify more then one availability zone, this plugin will also provision the following database-related resources:

  • AWS::RDS::DBSubnetGroup
  • AWS::ElastiCache::SubnetGroup
  • AWS::Redshift::ClusterSubnetGroup
  • AWS::DAX::SubnetGroup

to make it easier to create these resources across all of the availability zones.

Installation

$ npx sls plugin install -n serverless-vpc-plugin

Configuration

  • All vpcConfig configuration parameters are optional
# add in your serverless.yml

plugins:
  - serverless-vpc-plugin

provider:
  # you do not need to provide the "vpc" section as this plugin will populate it automatically
  vpc:
    securityGroupIds:
      -  # plugin will add LambdaExecutionSecurityGroup to this list
    subnetIds:
      -  # plugin will add the "Application" subnets to this list

custom:
  vpcConfig:
    cidrBlock: '10.0.0.0/16'

    # if createNatGateway is a boolean "true", a NAT Gateway and EIP will be
    # provisioned in each zone auto-discovered or specified below.
    # if createNatGateway is a number, that number of NAT Gateways will be provisioned
    createNatGateway: 2

    # When enabled, the DB subnet will only be accessible from the Application subnet
    # Both the Public and Application subnets will be accessible from 0.0.0.0/0
    createNetworkAcl: false

    # Whether to create the DB subnet
    createDbSubnet: true

    # Whether to enable VPC flow logging to an S3 bucket
    createFlowLogs: false

    # optionally specify AZs (defaults to auto-discover all availabile AZs)
    zones:
      - us-east-1a
      - us-east-1b
      - us-east-1c

    # by default, s3 and dynamodb endpoints will be available within the VPC
    # see https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints.html
    # for a list of available service endpoints to provision within the VPC
    # (varies per region)
    services:
      - kms
      - secretsmanager

CloudFormation Outputs

After executing serverless deploy, the following CloudFormation Stack Outputs will be provided:

  • VPC: VPC logical resource ID
  • LambdaExecutionSecurityGroup: Security Group logical resource ID that the Lambda functions use when executing within the VPC