Skip to content

Instantly share code, notes, and snippets.

@joebernard
Created January 5, 2022 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joebernard/100ba280fdeba61d4a06990ab860ea78 to your computer and use it in GitHub Desktop.
Save joebernard/100ba280fdeba61d4a06990ab860ea78 to your computer and use it in GitHub Desktop.
Cheap and easy NAT instance
# Inspired from here: https://www.kabisa.nl/tech/cost-saving-with-nat-instances/
NatInstance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t4g.micro
ImageId: ami-0a1eddae0b7f0a79f # Amazon Linux 2 AMI (HVM), SSD Volume Type, 64-bit ARM
SourceDestCheck: false
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeviceIndex: "0"
GroupSet:
- { Fn::GetAtt: [vpc, DefaultSecurityGroup] }
SubnetId:
Ref: "subnetPublic1"
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
sudo sysctl -w net.ipv4.ip_forward=1
sudo /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment