skip to Main Content

I am using CircleCI for my CI/CD along with CodeDeploy. I would like to run an ecs run-task command and would like the task to complete before moving on to the more intricate deployment stages, which we use CodeDeploy for, and is triggered through the CircleCI config. In a previous version of the aws cli the --wait flag was an option for this, but is not an option in aws version 2+. Are there any other simple alternatives that people are using to get around this?

2

Answers


  1. Chosen as BEST ANSWER

    Adding my solution here thanks to Mark B's response.

    TASK_ID=$(aws ecs run-task 
    --profile staging 
    --cluster <cluster-name> 
    --task-definition <task-definition> 
    --count 1 
    --launch-type FARGATE 
    --network-configuration "awsvpcConfiguration={subnets=[$SUBNET_ONE_STAGING, $SUBNET_TWO_STAGING, $SUBNET_THREE_STAGING],securityGroups=[$SECURITY_GROUP_IDS_STAGING],assignPublicIp=ENABLED}" 
    --overrides '{"containerOverrides":[{"name": "my-app","command": ["/bin/sh", "-c", "bundle exec rake db:migrate && bundle exec rake after_party:run"]}]}' 
    | jq -r '.tasks[0].taskArn') 
    && aws ecs wait tasks-stopped --cluster <cluster-name> --tasks ${TASK_ID}
    

  2. You would use the aws ecs wait capability in the CLI. Note that this is the same in version 1 of the CLI and version 2, there was never a --wait for ECS tasks in the core AWS CLI as far as I’m aware.

    Specifically, after starting the task and getting the task ID returned from the run-task command, you would use aws ecs wait task-stopped --tasks <task-id> to wait for the task to be done/stopped.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search