AWS更改记录设置为私有IP地址

时间:2018-10-10 16:20:52

标签: amazon-web-services amazon-route53

我正在尝试编写一个脚本,该脚本将允许实例在每次启动新记录时更新AWS中的记录集。 我正在遵循此指南: https://aws.amazon.com/premiumsupport/knowledge-center/simple-resource-record-route53-cli/

我的sample.json看起来像这样:

{
        "Comment": "CREATE/DELETE/UPSERT a record ",
        "Changes": [{
        "Action": "UPSERT",
                    "ResourceRecordSet": {
                                "Name": "test.mydomain.com",
                                "Type": "A",
                                "TTL": 300,
                             "ResourceRecords": [{ "Value": "4.4.4.4"}]
  }}]
}

我想用实例的专用IP地址替换4.4.4.4。 我尝试在其中插入$IP_ADDRESS,但显然没有用。

我还尝试通过执行以下操作手动输入:

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"}]}}]}

执行此操作时,我不断收到以下错误消息:

Unknown options: Changes:, [{Action:, UPSERT,, ResourceRecordSet:Name:test.mydomain.com}]}, ResourceRecordSet:Type:A}]}, ResourceRecordSet:TTL:300}]}, ResourceRecordSet:ResourceRecords:[{Value:}]}]}, UPSERT a record,

我尝试过多次重新格式化,但是总有问题。 每次启动新实例时,如何确定实例的IP地址已插入该记录集中?

1 个答案:

答案 0 :(得分:1)

由于需要转义引号,因此很难通过命令行传递JSON。

相反,将json放入文件中。执行如下命令:

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
相关问题