0

I've setup a cluster on AWS ECS, it's hosting nginx and a webapp.

I've used these commands to create my resources

aws ecr create-repository --repository-name <repo-name>

ecs-cli configure --cluster <cluster-name> --region eu-west-3 --config-name <conf-name> --cfn-stack-name <stack-name> --default-launch-type EC2

ecs-cli up --keypair <keypair> --capability-iam --size 1 --instance-type t2.medium --cluster-config <conf-name>

docker-compose build

docker-compose push

ecs-cli compose up --cluster-config <conf-name>

I've also setup a service in that cluster connected to the task created above.

My goal is to be able to push the docker images (That already works) and then use some command to get ECS to fetch the new images and load them up (this is where I'm stuck). I have to do this through the CLI since I want to automate this later on.

My question is: Should I just delete the running task so that the service will replace it? This works if I do it in the AWS Management console. But it causes downtime of my webservice.

Another options is to use the command below which I found here:

aws ecs update-service --cluster <cluster name> --service <service name> --force-new-deployment

However, when I run that command I get this error:

EVENTS  2021-04-21T05:32:45.842000-07:00        2c47e2c0-3a76-4dc1-bfef-21392b65871b    (service <service-name>) was unable to place a task because no container instance met all of its requirements. The closest matching (container-instance 25785de8f80041e0afd7b0adfda5f2fa) is already using a port required by your task. For more information, see the Troubleshooting section of the Amazon ECS Developer Guide.
EVENTS  2021-04-21T05:29:11.592000-07:00        4279fb7c-9c36-477b-acb3-173edb8e2c31    (service <service-name>) has reached a steady state.

I'm guessing it can't create another EC2 instance because I've set the number of instances to 1 on creation of my cluster. But I tried with 2 instances and it seems overkill to have two instances up and running all the time. How can I achieve this?

2

AWS container service team member here. IF you are still early on in your journey to automate this via a CLI I would suggest you consider moving past the ecs-cli. The follow-on version of this CLI is called AWS Copilot and has more sophistication to implement those workflows. Note that Copilot dropped support for docker compose because we have implemented a native integration with Docker and the new docker compose cli. You can read more here and here.

7
  • 1
    Thank you! Copilot seems like it could help me alot. Do you know a noob-friendly guide launching a docker compose project with AWS Copilot? Containers are very new for me so I could not really understand how I would use the info in the links you attached in Copilot. Apr 21 at 14:23
  • 2
    Yes sorry, pointing to the root of the docs may be too overwhelming :) You may want to start with this one from the docs .... or with this one from the blogs for a more step-by-step first guided experience.
    – mreferre
    Apr 22 at 6:55
  • 2
    But I'd like to hear more from you if either fits your need (as someone completely new to container and of course Copilot) or if you need something different (care to elaborate more on what exactly?). Thanks!
    – mreferre
    Apr 22 at 6:57
  • 1
    Thank you very much! Basically I have a web-app I've made in Django. I'm running this project with Django, Gunicorn and Nginx. I've split this in two containers, One with Django files and running gunicorn and the second with Nginx. I also have a docker-compose.yml that just point to the images. My goal is basically to have some pipeline so that when I use git push some tests will run and the automatically deploy my containers. Right now I have automatic testing and pushing of images to my ECR registry. But the last step of autodeploy is where I'm stuck. Do you think Co-pilot is a good fit? Apr 22 at 7:40
  • 2
    I think I got my project to work using the method described in the link in your initial post! I really appreciate you taking the time to help me, thank you! Apr 22 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.