Wondering how to use the static or elastic IP address for the ECS task on Fargate? We can help you with this!
As a part of our AWS Support Services, we often receive similar requests from our AWS customers.
Today, let’s see the steps followed by our Support Techs to help our customers to add a static IP address or Elastic IP address to a Fargate task.
Use the static or elastic IP address for the ECS task on Fargate
We can’t directly assign a static or elastic IP address to an ECS task on Fargate. So for creating a static IP address, we must use a Network Load Balancer with an Elastic IP address and Fargate service.
Let’s see the steps for creating a static IP address for a Fargate task for inbound traffic:
Creating a network load balancer
- Log in to the AWS Management console and then open the Amazon EC2 console.
2. Select Load Balancers from the section LOAD BALANCING.
3. Then select Create Load Balancer.
4. Select Create for Network Load Balancer from the load balancer type section.
5. Then enter a name for the load balancer for the Name option on the Configure Load Balancer page.
6. Select external or internal-facing for the Scheme option.
7. Add another listener or keep the default (accepts TCP traffic on the port 80)one for Listeners. Here we can modify the port and protocol of the default listener or we can select the option Add listener to add another listener.
8. Select the Amazon VPC as VPC for our Fargate task in the Availability Zones section. To associate an Elastic IP address with the subnet, select the IP address from Elastic IP.
9. Now, Skip the Next: Configure Security Settings page.
10. Then select Next: Configure Routing.
Configure Routing for the target group
- Select New target group for Target group on the Configure Routing page.
2. Enter a name for the target group for Name and select Instance or IP (Select IP to register the targets with an IP address) for the Target type.
3. Then enter the protocol for Protocol and enter the port for the option Port.
4. Keep the default settings for the Health checks section and then select Next: Register Targets. Here we don’t add targets to the target group as Amazon ECS handles target registration. Amazon ECS automatically registers and deregisters containers with the target group.
5. So we can skip the Register Targets page.
6. Select Next: Review, and then select Create.
Creating an Amazon ECS service
Now we can create an Amazon ECS service. Make sure to specify the target group in the service definition while creating the service.
When each task is started, the container and port defined in the service definition are registered with the target group. And the traffic is then routed from the load balancer to the container.
Note: To create a static IP address for a Fargate task for outbound traffic, create a NAT gateway. In this scenario, a static IP address is required by the downstream consumer. We must place the Fargate task on a private subnet. We can use the NAT gateway IP address for an IP allow list.
[Need help with more AWS queries? We’d be happy to assist]
Conclusion
To conclude, today we discussed the steps followed by our Support Engineers to help our customers to add the static or elastic IP address for the ECS task on Fargate.
0 Comments