Reputation: 1603
I'm trying to write a script that would allow the instances to update a record set in AWS each time a new one is spun up. I'm following this guide: https://aws.amazon.com/premiumsupport/knowledge-center/simple-resource-record-route53-cli/
My sample.json looks like this:
{
"Comment": "CREATE/DELETE/UPSERT a record ",
"Changes": [{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "test.mydomain.com",
"Type": "A",
"TTL": 300,
"ResourceRecords": [{ "Value": "4.4.4.4"}]
}}]
}
I want to replace the 4.4.4.4
but with instance's private IP address.
I tried inserting $IP_ADDRESS
there, but obviously, it didn't work.
I also tried entering this manually by doing this:
IP_ADDRESS=$(curl http://169.254.169.254/latest/meta-data/local-ipv4)
aws route53 change-resource-record-sets --hosted-zone-id HKJA837HJS --change-batch {"Comment": "UPSERT a record", "Changes": [{"Action": "UPSERT", "ResourceRecordSet":{"Name":"test.mydomain.com","Type":"A","TTL":300,"ResourceRecords":[{"Value":"$IP_ADDRESS"}]}}]}
When I do this I keep getting the following error:
Unknown options: Changes:, [{Action:, UPSERT,, ResourceRecordSet:Name:test.mydomain.com}]}, ResourceRecordSet:Type:A}]}, ResourceRecordSet:TTL:300}]}, ResourceRecordSet:ResourceRecords:[{Value:}]}]}, UPSERT a record,
I tried re-formatting this numerous times but there's always something wrong. How can I make sure the instance's IP address is inserted in that recordset each time a new instance in launched?
Upvotes: 0
Views: 329
Reputation: 81414
Trying to pass JSON via the command line is very difficult to get correct because of the need to escape your quote marks.
Instead put your json into a file. Execute a command like this:
sed "s/4.4.4.4/$NEWIP/g" update_rr.json
aws --profile PROD route53 change-resource-record-sets --hosted-zone-id ABCDEFGH012345 --change-batch file://update_rr.json
Upvotes: 1