Quantcast
Channel: Store JSON directly in bash script with variables? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Store JSON directly in bash script with variables?

$
0
0

I'm going to preface by saying that "no, find a different way to do it" is an acceptable answer here.

Is there a reliable way to store a short bit of JSON in a bash variable for use in a AWS CLI command running from the same script?

I'll be running a job from Jenkins that's updating an AWS Route53 record, which requires UPSERTing a JSON file with the change in records. Because it's running from Jenkins, there's no local storage where I can keep this file, and I'd really like to avoid needing to do a git checkout every time this project will run (which will be once an hour).

Ideally, storing the data in a variable ($foo) and calling it as part of the change-resource-record-sets command would be most convenient given the Jenkins setup, but I'm unfamiliar with exactly how to quote/store JSON inside bash - can it be done safely?

The specific JSON in this case is the following;

{"Comment":"Update DNSName.","Changes":[{"Action":"UPSERT","ResourceRecordSet":{"Name":"alex.","Type":"A","AliasTarget":{"HostedZoneId":"######","DNSName":"$bar","EvaluateTargetHealth":false}}}]}

As an added complication the DNSName value - $bar - needs to be expanded.


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images