Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CloudFormation template implementing Private network which can be used by Serverless to deploy Lambda into VPCs an maintaining internet access
# Add the following to your existing VPC CF stack
# create 2 subnets, lambdas like to be in multiple subnets
Private1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs ]
CidrBlock: !Ref Private1CIDR
Private2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs ]
CidrBlock: !Ref Private2CIDR
NATIP:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
NatGateway:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NATIP.AllocationId
SubnetId: !Ref Subnet1 # PUBLIC SUBNET!
PrivateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub "${Name} Private (Lambda)"
DefaultPrivateRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway
Private1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRouteTable
SubnetId: !Ref Private1
Private2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRouteTable
SubnetId: !Ref Private2
Outputs:
PrivateSubnet1:
Value: !Ref Private1
Export:
Name: !Sub "${Pipe}-PrivateSubnet1"
PrivateSubnet2:
Value: !Ref Private2
Export:
Name: !Sub "${Pipe}-PrivateSubnet2"
@65

This comment has been minimized.

Copy link

65 commented Dec 31, 2017

I think you are missing some parts here, you have

SubnetId: !Ref Subnet1 # PUBLIC SUBNET!

but there is no item names Subnet1

@brandonrobertz

This comment has been minimized.

Copy link

brandonrobertz commented Mar 27, 2018

I think you're supposed to feed Subnet1 as an input variable, leaving that up to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.