0

I’m using Terraform to upload a web to AWS. This ECS, with a docker image, that errors with 500 when I try to go to it’s assigned A-record DNS name. For this service, I’ve assigned a few AWS resources:

  • AWS role
  • AWS policy
  • AWS elastic load balancer (elb)
  • AWS ecs cluster
  • AWS ecs service
  • AWS ecs task definition

The Docker image:

<some-image>

The corresponding configuration is:

"portMappings": [
  {
    "containerPort": 80,
    "hostPort": 80
  }
]

Running the docker container locally, gives me a successful response. So clearly I’m missing some resources.

I asked around and it seems the elb doesn’t have a backing container host. Does that mean I need an ec2 ami and instance? Here's what my aws terraform config looks like (with my failed attempts at ami and instance configs).

I don’t see a way in terraform, to point those resources to an secs cluster or service. Going the opposite direction, nowhere in the ECS cluster, service or task definition, do I see a way to define an AWS ami or instance. How do I configure this in terraform?

Frye
  • 253
  • 3
  • 11
  • Did you check this out http://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_container_instance.html – error2007s Jun 12 '16 at 13:28
  • @error2007s I did, and was able to set up a running EC2 instance, that's attached as one of my ECS service instances. I can even reach it's A-record domain name. But **A)** while connecting to it doesn't 400 or 503, it just hangs, as there's no code behind it. And **B)** employing my docker image is the whole point of using ECS. So how do I get *i)* my docker image to *ii)* be used by AWS' AMI, which *iii)* should be visible from my ELB? – Frye Jun 12 '16 at 21:42

1 Answers1

0

In short, you should not relate ALB/ELB directly with instances inside the ECS Cluster. It is possible to do, but is not aligned with vision of the tool. If that is what you want, you can create EC2 instance running docker, and manage the start/stop of containers yourself.

If you wish to use ECS Services and Clusters to manage your container placement for you, you can do by this. Done via terraform, cli, cloudformation, ansible, etc..

  1. Create ECS Cluster, to establish name and arn

  2. Create IAM Roles for ECS Service and ECS Cluster Instance. These are specified in the docs and created if you launch the demo cluster.

  3. Create EC2 Launch Config which specifies the correct cluster name in the user data script

  4. If necessary, Create EC2 Security Groups, VPC, Subnet to your desired setup

  5. Create an Auto Scale Group which incorporates items in steps 2,3 and 4. This will be used to control the size of your ECS cluster

  6. Create ECR reposoitory which will be used to store your docker images. You can pull also from private docker registry, but there would be additional steps within Step #3.

  7. Create task definitions which will be used to describe how ECS is supposed to run your docker containers. Task definitions mimic the spirit of docker-compose, but are their own thing, so you will have to read up.

  8. Create ALB to act as the LB for your web service. This will accept traffic from clients and route to the running docker containers.

  9. Create an ECS Service which will link your ALB to your Web Service running on docker

Upload your docker image to the ECR repository created in step #6.

The ECS Service will manage the number of Web Services running within the cluster and ensure they are joined to the correct ALB.

JD Williams
  • 134
  • 3