Forked from romaninsh/lambda-vpc-internet-access-cloudformation.yml
Created
June 25, 2019 16:36
-
-
Save 030/c21e2f263c6c9937d780b5a94116218a 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
Thanks for this!