I am new to AWS and encountered some problem while trying to create a EC2 service in a ECS cluster.
I was able to successfully create a brand new service (service1
) in cluster1
, but afterwards, I decided to delete cluster1
and create cluster2
. The problem came when I try to re-create service1
in cluster2
. Whenever I try to add the service, I will get the following error
creation failed: Service already exists. (Service: AWSServiceDiscovery; Status Code: 400; Error Code: ServiceAlreadyExists; Request ID: d854025e-ebcc-11e8-84ab-b3bac906f2ef)
Does anyone know how to resolve this problem? I have tried deregistering the task definition but it didn't work. cluster1
has been deleted and there are no services in cluster2
.
Here is full answer. When you created AWS ECS Service and you have also selected optional ServiceDiscovery for it as well which created an namespace(.local) and service(with same name as ECS Service) in Route53.
When you deleted ECS service & cluster, it won't automatically delete Route53 namespace/service entries. Now, you are getting Service already exists
error since your new ECS Service matches with same name as ServiceDiscovery service. You have 3 options. 1. Clean up Route53 namespaces and services. 2. Re-use Route53 Service if you want to continue to use ServiceDiscovery feature. 3. Don't enable service discovery integration when you are creating ECS Service.
Option 1 -
aws servicediscovery list-services
{ "Services": [ { "Id": "srv-x4acveybedar32mv", "Arn": "arn:aws:servicediscovery:us-east-1:1234567890:service/srv-x4acveybedar32mv", "Name": "nginx" } ] }
aws servicediscovery list-namespaces
{ "Namespaces": [ { "Id": "ns-3yd7pskwsxhwlq67", "Arn": "arn:aws:servicediscovery:us-east-1:1234567890:namespace/ns-3yd7pskwsxhwlq67", "Name": "local", "Type": "DNS_PRIVATE" } ] }
aws servicediscovery delete-service --id "srv-x4acveybedar32mv"
. Result is empty response from CLI.aws servicediscovery delete-namespace --id "ns-3yd7pskwsxhwlq67"
{ "OperationId": "s573v5dr62yee5d7vbfvsy5h65ybxmoh-jossalgs" }
Sometimes, DNS cleanup operations will take couple of minutes to reflect properly so just give always few minutes before retrying.
Option 2 -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With