I have a requirement where I was to call firewall-protected service from ecs container. IP can be added to the firewall white list however I am struggling to get static IP for my ecs service. Below are things that I tried
- Created NAT instances
- Provided static IP to NAT instance (Idea is to use this IP for whitelisting)
- Created a subnet with a route table to direct all outgoing traffic (0.0.0.0/0) to NAT instance (nat instance interface id)
- Attached by ecs to the subnet created in step 4
After this setup when I am trying to bring up by ecs task it fails to connect to S3, ecr, log etc. So I created vpc endpoint for these services (s3, log, ecr). After endpoint creation error is gone however now an error coming for appconfig. I tried finding appconfig service to create its endpoint but there is no service with name appconfig. Also this method of creating an endpoint for everything doesn't look feasible.
AWS experts please help in bringing up the ecs which have static IP for outbound traffic. So that it can be whitelisted.
Update : Steps I followed to setup Nat Instance
- created new instance with "Auto-assign Public IP" to ensure the instance gets a public IP address.
- Associated Elastic IP address" to instance
- Ran below commands in instance sudo sysctl -w net.ipv4.ip_forward=1 sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE edit the /etc/sysctl.conf file and add the following line: Copy code net.ipv4.ip_forward = 1 Save the changes and exit the editor.
- Disabled the source/destination check on the NAT instance
- edited route table of ecs task. In the "Destination" field, entered "0.0.0.0/0"(to route all internet-bound traffic). In the "Target" field, choose NAT instance