amazon-ecsaws-route53

How to get the url of ecs service


I need to obtain the ECS service URL to make requests to its endpoints for information.

I am currently using AWS Lambda to interact with the service. Although I have tried making requests using the service's private IP (both the service and Lambda are in the same VPC), this approach has not been successful. Therefore, I believe it would be more effective to use the service URL for these requests.


Solution

  • There is no such thing as an ECS "service URL". You would have to add a load balancer in front of the ECS service, and then use the load balancer's URL. And for what you are doing (internal VPC traffic) it would need to be an internal load balancer with no public IP address.

    However, your attempt to use the private IP of the ECS task, from a Lambda function in the VPC, should absolutely work. If it isn't working then you should provide more information about your configuration so we can help you, such as the ECS task's network mode setting, and the details of the security group assigned to the ECS service.

    In general, to make it work you will need to assign a security group to your Lambda function. That security group will need to have the default rule allowing outbound traffic, and it doesn't need any inbound rules. Then for your ECS service, you will need to have a security group assigned to it that allows inbound traffic (on whatever port your ECS tasks listen on) with the source being the security group ID of your Lambda function.