CodexBloom - Programming Q&A Platform

AWS ECS Service Discovery Not Resolving DNS for Newly Deployed Tasks

👀 Views: 78 💬 Answers: 1 📅 Created: 2025-08-06
aws ecs service-discovery cdk TypeScript

I’m working with an scenario with AWS ECS where newly deployed tasks in my Fargate service are not resolving DNS names when using AWS Cloud Map for service discovery. My setup uses the latest version of the AWS CDK (1.134.0) to provision the resources. I have configured a private namespace in Cloud Map, and the ECS service is set up to use this namespace. Despite the services being correctly registered in Cloud Map, when I attempt to access them using the service name from another task, I get the following behavior: `SERVICENAME.local: Name or service not known`. I’ve checked the security groups and VPC configurations and they seem correct, allowing traffic on the required ports. I’ve tried adding a `health check` to the ECS service definition, hoping it would resolve the scenario, but that hasn’t helped. Here’s the relevant part of my CDK stack code: ```typescript const vpc = new ec2.Vpc(this, 'MyVpc', { maxAzs: 2 }); const namespace = new servicediscovery.PrivateDnsNamespace(this, 'MyNamespace', { name: 'local', vpc, }); const cluster = new ecs.Cluster(this, 'MyCluster', { vpc }); const taskDefinition = new ecs.FargateTaskDefinition(this, 'MyTaskDef'); // Add container definition here const service = new ecs.FargateService(this, 'MyService', { cluster, taskDefinition, cloudMapOptions: { name: 'SERVICENAME', cloudMapNamespace: namespace, }, }); ``` I ensured that the task’s IAM role has `service-discovery:DiscoverInstances` permissions, but still no luck. Is there something I'm missing in the configuration, or is there a common scenario related to service discovery in ECS that I should be aware of? Any suggestions would be greatly appreciated!