Consider the AWS CLI commands in a script file
#!/bin/bash
msgClr='\033[1;35m'
errClr='\033[1;31m'
cynClr='\033[1;36m'
NC='\033[0m'
#Read CLuster from command Args
cluster="MyCluster"
#Update Service
echo -e "${msgClr}Initiate: ${NC}Updating Service..."
serviceName=$(aws ecs list-services --cluster $cluster | jq '.serviceArns[0]')
allTaskDefs=$(aws ecs list-task-definitions | jq '.taskDefinitionArns')
taskDefLength=$(echo $allTaskDefs | jq '. | length')
latestTaskDefArn=$(echo $allTaskDefs | jq '.['`expr $taskDefLength - 1`']')
#latestTaskDef=$(echo $latestTaskDefArn | awk 'BEGIN{FS="/"}{print substr($2, 1, length($2)-1)}')
#echo -e "${msgClr}Using Task Definition: ${cynClr}"$latestTaskDef"${NC}"
echo "aws ecs update-service --cluster $cluster --task-definition $latestTaskDefArn --service $serviceName"
$(aws ecs update-service --cluster $cluster --task-definition $latestTaskDefArn --service $serviceName)
echo -e "${msgClr}Complete: ${NC}Updating Service..."
It fails with
An error occurred (InvalidParameterException) when calling the UpdateService operation: Invalid revision number. Number: aws:ecs:eu-west-1:630026061543:task-definition/ecscompose-production:33"
but if I echo out the last command
$(aws ecs update-service --cluster $cluster --task-definition $latestTaskDefArn --service $serviceName)
and copy paste it, it runs smoothly. Why and what am I doing wrong?