title: Deploying flask application on AWS ECS
body: <p>I created a sample flask application by following Corey Schafer videos available on youtube. I am able to run in local environment and its working fine. I want to deploy it in AWS ECS cluster with fargate option so that I don't have to manage EC2 instances. I was able to build a sample cluster and service using terraform. Below is the code(Application load balancer part is missing)</p>
  <pre><code>provider &quot;aws&quot; {
    region = &quot;us-east-2&quot;
  }
  
  
  resource &quot;aws_ecs_cluster&quot; &quot;sample_cluster&quot; {
    name = &quot;sample_cluster&quot;
  
    setting {
      name  = &quot;containerInsights&quot;
      value = &quot;enabled&quot;
    }
  }
  
  data &quot;aws_iam_role&quot; &quot;ecs_task_execution_role&quot; {
    name = &quot;ecsTaskExecutionRole&quot;
  }
  
  resource &quot;aws_ecs_task_definition&quot; &quot;sample_cluster_task_definition&quot; {
    container_definitions = file(&quot;templates/container_definition.json&quot;)
    family                = &quot;sample_terraform_task_definition&quot;
    cpu                   = 256
    memory                = 512
    execution_role_arn    = data.aws_iam_role.ecs_task_execution_role.arn
    network_mode          = &quot;awsvpc&quot;
    runtime_platform {
      operating_system_family = &quot;LINUX&quot;
      cpu_architecture        = &quot;X86_64&quot;
    }
    requires_compatibilities = [&quot;FARGATE&quot;]
  }
  
  data &quot;aws_subnets&quot; &quot;private&quot; {
    filter {
      name   = &quot;vpc-id&quot;
      values = [&quot;vpc-ac6d734yrbfjd7ebc7&quot;]
    }
  
  }
  
  
  
  
  resource &quot;aws_ecs_service&quot; &quot;sample_service&quot; {
    name            = &quot;sample_ecs_service&quot;
    cluster         = aws_ecs_cluster.sample_cluster.arn
    task_definition = aws_ecs_task_definition.sample_cluster_task_definition.arn
    launch_type     = &quot;FARGATE&quot;
    desired_count = 1
    network_configuration {
      subnets          = toset(data.aws_subnets.private.ids)
      security_groups = [&quot;sg-0044394c6e4b485738762f7&quot;]
      assign_public_ip = &quot;true&quot;
    }
    depends_on = [aws_ecs_task_definition.sample_cluster_task_definition,data.aws_subnets.private ,aws_ecs_cluster.sample_cluster]
  }
  </code></pre>
  <p>I am struggling with how(if required) to configure a web server in AWS since local environment has a dev server which is not suitable for production environment. So my question is</p>
  <ol>
  <li>For a webserver e.g. nginx will it be separate docker container or  does AWS has any managed service which can be utilized as a web server. For instance I am using AWS RDS instead of a separate container for DB.</li>
  <li>If a separate docker container is required will it be part of same task definition or different. Which one is recommended.</li>
  </ol>
  <p>I just want to give deployment more like a actual production setup so in case if anyone has deployed flask application in aws ecs in production could you please help me out. Thank you</p>