title: Questions about running redis as an ECS service + service discovery
body: <p>I'm trying to understand how service discovery / cloudmap works with ECS. I have a toy repo (link below) with a simple flask app that gets and sets the <code>foo</code> key from redis. It works as expected locally in docker-compose, and I am working on a terraform configuration (in the same repo) to make this work in ECS so that the flask task can communicate to the redis task.</p>
  <p>I think I'm close to making this work, but I'm getting the following error in flask for routes that make calls to redis:</p>
  <pre><code>redis.exceptions.ConnectionError: Error -2 connecting to default-redis.default-sd-ns:6379. Name or service not known.
  </code></pre>
  <ul>
  <li><code>default-redis.default-sd-ns</code> is the name of the service discovery service and CloudMap private dns namespace. It is the value for the <code>REDIS_HOST</code> environment variable in my flask app.</li>
  <li>there is an <code>A</code> record in Route 53 for <code>default-redis.default-sd-ns</code> that points to the private IP of the redis task in ECS</li>
  <li>I'm using Fargate launch types for both the flask app and the redis service. The flask app is passing health checks and I can access it over it's the subdomain that I configured it to run on.</li>
  </ul>
  <p>Here's a link to the git repo where I'm work on this toy project and terraform configuration: <a href="https://github.com/briancaffey/flask-redis-ecs-terraform" rel="nofollow noreferrer">flask-redis-ecs-terraform</a>. Does anyone have an example project that shows how to configure a service like redis with CloudMap so that other tasks can communicate with it?</p>
  <p>I was previously trying to do this with EC2 launch types, but I ran into ENI errors that prevented tasks from being placed. I have done a lot searches for examples, but I can't find anything that has been able to give me a complete example of this type of task &lt;-&gt; task communication.</p>
  <p>Does anyone have any ideas about how I could debug the connectivity issue between my flask app and the redis service in ECS?</p>
  <hr />
  <p>One a separate topic, I'm doing this to support containerized ad-hoc development environments that can be used to rapidly test new features. Instead of trying to use a shared, always on ElastiCache instance, or use ElastiCache instances per ad-hoc environment, I wanted to try to use a standalone redis service in ECS per environment. This small change has resulted in a lot of changes to the terraform configuration, particularly with respect to networking settings. I was originally using <code>bridge</code> networking and didn't need to worry about communication between tasks. I probably won't be using any service discovery in other more permanent / stable environments since I can rely on ElastiCache for using redis. Does this make sense?</p>
  <p>I'm currently working on configuring ECS Exec to see if I can query that Route 53 record from my app container.</p>