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?

Felix Eklöf
  • 239
  • 2
  • 9

1 Answers1

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.

mreferre
  • 256
  • 1
  • 2