Last active
December 22, 2021 00:26
-
-
Save romaninsh/81d4ee778c1e20f709f3518c22521ba4 to your computer and use it in GitHub Desktop.
CloudFormation template implementing Private network which can be used by Serverless to deploy Lambda into VPCs an maintaining internet access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you're supposed to feed Subnet1 as an input variable, leaving that up to you.