
여러 주소로 라우팅되는 호스팅 영역과 레코드 세트가 있습니다. 목록에서 IP 주소를 추가하거나 제거하여 레코드세트를 업데이트하고 싶습니다. 안타깝게도 AWS CLI는 Route53의 리소스 레코드 값을 삭제/추가하는 옵션을 제공하지 않습니다.
{
"Comment": "Update the A record set",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "mydomain.com",
"Type": "A",
"TTL": 300,
"ResourceRecords": [
{
"Value": "XX.XX.XX.XX"
}
]
}
}
]
}
이와 같이 json에 여러 IP 주소를 수동으로 추가할 수 있습니다.하지만 bash를 사용하여 json 파일에 여러 IP를 자동으로 추가하고 싶습니다.
{
"Comment": "Update the A record set",
"Changes": [{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "mydomain.com",
"Type": "A",
"TTL": 300,
"ResourceRecords": [{
"Value": "XX.XX.XX.XX"
},
{
"Value": "XX.XX.XX.XX"
}
]
}
}]
}
답변1
추가하다, 사용하다잭
$ jq '.Changes[0].ResourceRecordSet.ResourceRecords += [{"Value": "foobar"}]' file.json
{
"Comment": "Update the A record set",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "mydomain.com",
"Type": "A",
"TTL": 300,
"ResourceRecords": [
{
"Value": "XX.XX.XX.XX"
},
{
"Value": "foobar"
}
]
}
}
]
}
답변2
시도해 볼 수 있는 또 다른 UNIX 유틸리티가 있습니다:jtc
, 파일 내에서 변경 사항을 적용할 수 있습니다( -f
옵션 포함):
bash $ jtc -w'<ResourceRecords>l' -i'{ "Value": "YY.YY.YY.YY" }' -f file.json
bash $ jtc file.json
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "mydomain.com",
"ResourceRecords": [
{
"Value": "XX.XX.XX.XX"
},
{
"Value": "YY.YY.YY.YY"
}
],
"TTL": 300,
"Type": "A"
}
}
],
"Comment": "Update the A record set"
}
bash $
항목을 삭제합니다.
bash $ jtc -w'<ResourceRecords>l [0]' -p -f file.json
bash $ cat file.json
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "mydomain.com",
"ResourceRecords": [
{
"Value": "YY.YY.YY.YY"
}
],
"TTL": 300,
"Type": "A"
}
}
],
"Comment": "Update the A record set"
}
bash $