-1

Below is my taskdef.json and want to update few values dynamically using shell script, I'm trying to use JQ but doesn't seem to work as expected.

{
    "containerDefinitions": [{
      "logConfiguration": [{
        "logDriver": "fluentd",
        "options": {
          "tag": "fluentd demo"
        },
        "secretOptions": [{
          "name": "fluentd-address",
          "valueFrom": "arn:aws:ssm:region:aws_account_id:parameter:parameter_name"
        },
        {
            "name": "fluentd-name",
          "valueFrom": "arn:aws:ssm:region:aws_account_id:parameter:parameter_name"
        }
    ]
      }]
    }]
  }

I want the region and aws_account_id to be updated dynamically instead of hardcoding the value directly inside the taskdef.json.Is there a way to update these value?

chris
  • 324
  • 3
  • 17

1 Answers1

0

Not sure if the use of jq is required or not, but you can simplly use sed to do the replacement:

region="us-east-1"
account_id="12345"

sed "s/region/${region}/g; s/aws_account_id/${account_id}/g" /path/to/taskdef.json

if you want to permanently change the values in the input file, add -i:

sed -i "s/region/${region}/g; s/aws_account_id/${account_id}/g" /path/to/taskdef.json
Marcin
  • 215,873
  • 14
  • 235
  • 294