Hello Team i need an assistance in replacing the current ecs task defintion revision in json file. I'm able to replace the values for awsNetworkSubnet in variables.json successfully.
But struggling to create apprpriate sed command for revision no (which is 7 in sample variables.json below)
Bash Script:
#!/bin/bash
Input_file=$1
ENV=$2
Commit_id=$3
subnet_id=$(aws ec2 describe-subnets --filter "Name=tag:use,Values=data" --query "Subnets[*].SubnetId" --output json | jq -r '.[0]')
echo "Subnet ID: ${subnet_id}"
airflow_ecs_task_definition_revision=$( aws ecs describe-task-definition --task-definition airflow_ecs-small --output json | jq '.taskDefinition.revision')
echo "ECS Task Definition Revision: ${airflow_ecs_task_definition_revision}"
sed -i $1 \
-e "/\"awsNetworkSubnet\":/ s/\"awsNetworkSubnet\":[^,]*/\"awsNetworkSubnet\":\"${subnet_id}\"/"
Sample Json file (variables,json)
"awsCluster": "airflow_ecs-dev",
"awsContainerName": "airflow_ecs",
"awsNetworkSubnet": "subnet-1234",
"awsRegionName": "us-east-1",
"awsSecurityGroup": "sg-1234",
"awsTaskDefinition": "airflow_ecs-small:7"
},
AWS CLi Used:
./subnet-cicd.sh variables.json test cmt1234