title: Get service Name of Task under aws fargate
body: <p>We need to get the service name under which a fargate task runs so we can perform some per service configuration (we have one service per customer, and use the service name to identify them). </p>
  
  <p>By knowing the service discovery namespace for our cluster and the Task IP address, we are able to do find out the service by doing the following.</p>
  
  <ol>
  <li>Get the task ip address, eaither by calling <a href="http://169.254.170.2/v2/metadata" rel="nofollow noreferrer">http://169.254.170.2/v2/metadata</a> endpoint or by using the ECS_ENABLE_CONTAINER_METADATA method in my follow-up answer.</li>
  <li>With the cluster namespace we call AWS.ServiceDiscovery.listNamespaces
  From there we extract the nameSpace id.</li>
  <li>We pass that to AWS.ServiceDiscovery.listServices</li>
  <li>We pass the id of each service to AWS.ServiceDiscovery.listInstances </li>
  <li>We flat map the results of that and look for an instance that matches our IP address above.</li>
  </ol>
  
  <p>Voilà! that record gives us the service name.</p>
  
  <p>Works fine, it just seems like a super circuitous path!  I'm just wondering whether there is some shorter way to get this information.</p>