<p>Today when I launch an app using kubernetes over aws it exposes a publicly visible LoadBalancer Ingress URL, however to link that to my domain to make the app accessible to the public, I need to manually go into the aws route53 console in a browser on every launch.  Can I update the aws route53 Resource Type A to match the latest Kubernetes LoadBalancer Ingress URL from the command line ?</p>

<p>Kubernetes over gcloud shares this challenge of having to either predefine a Static IP which is used in launch config or manually do a browser based domain linkage post launch.  On aws I was hoping I could use something similar to this from the command line </p>

<pre><code>aws route53domains update-domain-nameservers   ???
</code></pre>

<p>__ OR __ can I predefine an aws kubernetes LoadBalancer Ingress similar to doing a predefined Static IP when over gcloud ?</p>

<p>to show the deployed app's LoadBalancer Ingress URL issue</p>

<pre><code>kubectl describe svc
</code></pre>

<p>... output</p>

<pre><code>Name:           aaa-deployment-407
Namespace:      ruptureofthemundaneplane
Labels:         app=bbb
            pod-template-hash=4076262206
Selector:       app=bbb,pod-template-hash=4076262206
Type:           LoadBalancer
IP:         10.0.51.82
LoadBalancer Ingress:   a244bodhisattva79c17cf7-61619.us-east-1.elb.amazonaws.com
Port:           port-1  80/TCP
NodePort:       port-1  32547/TCP
Endpoints:      10.201.0.3:80
Port:           port-2  443/TCP
NodePort:       port-2  31248/TCP
Endpoints:      10.201.0.3:443
Session Affinity:   None
No events.
</code></pre>

<p>UPDATE:</p>

<p>Getting error trying new command line technique (hat tip to @error2007s comment) ... issue this</p>

<pre><code>aws route53 list-hosted-zones
</code></pre>

<p>... outputs</p>

<pre><code>{
    "HostedZones": [
        {
            "ResourceRecordSetCount": 6, 
            "CallerReference": "2D58A764-1FAC-DEB4-8AC7-AD37E74B94E6", 
            "Config": {
                "PrivateZone": false
            }, 
            "Id": "/hostedzone/Z3II3949ZDMDXV", 
            "Name": "chainsawhaircut.com."
        }
    ]
}
</code></pre>

<p>Important bit used below :  hostedzone  Z3II3949ZDMDXV</p>

<p>now I craft following <a href="http://docs.aws.amazon.com/Route53/latest/APIReference/CreateAliasRRSAPI.html" rel="noreferrer">using this Doc</a>  <a href="http://docs.aws.amazon.com/cli/latest/reference/route53/change-resource-record-sets.html" rel="noreferrer">(and this Doc as well)</a> as file /change-resource-record-sets.json (NOTE I can successfully change Type A using a similar cli call ... however I need to change Type A with an Alias Target of LoadBalancer Ingress URL)</p>

<pre><code>{
    "Comment": "Update record to reflect new IP address of fresh deploy",
    "Changes": [{
        "Action": "UPSERT",
        "ResourceRecordSet": {
            "Name": "chainsawhaircut.com.",
            "Type": "A",
            "TTL": 60,
            "AliasTarget": {
                "HostedZoneId": "Z3II3949ZDMDXV",
                "DNSName": "a244bodhisattva79c17cf7-61619.us-east-1.elb.amazonaws.com",
                "EvaluateTargetHealth": false
            }
        }
    }]
}
</code></pre>

<p>on command line I then issue</p>

<p>aws route53 change-resource-record-sets --hosted-zone-id Z3II3949ZDMDXV --change-batch file:///change-resource-record-sets.json</p>

<p>which give this error message</p>

<pre><code>An error occurred (InvalidInput) when calling the ChangeResourceRecordSets operation: Invalid request
</code></pre>

<p>Any insights ?</p>

<p>Here is the logic needed to update aws route53 Resource Record Type A with value from freshly minted kubernetes LoadBalancer Ingress URL</p>

<p>step 1 - identify your hostedzone Id by issuing</p>

<pre><code>aws route53 list-hosted-zones
</code></pre>

<p>... from output here is clip for my domain</p>

<pre><code>"Id": "/hostedzone/Z3II3949ZDMDXV", 
</code></pre>

<p>... importantly never populate json with hostedzone Z3II3949ZDMDXV its only used as a cli parm ... there is a second similarly named token HostedZoneId which is entirely different</p>

<p>step 2 - see current value of your route53 domain record ... issue :</p>

<pre><code>aws route53 list-resource-record-sets --hosted-zone-id Z3II3949ZDMDXV --query "ResourceRecordSets[?Name == 'scottstensland.com.']"
</code></pre>

<p>... output</p>

<pre><code>[
    {
        "AliasTarget": {
            "HostedZoneId": "Z35SXDOTRQ7X7K", 
            "EvaluateTargetHealth": false, 
            "DNSName": "dualstack.asomepriorvalue39e7db-1867261689.us-east-1.elb.amazonaws.com."
        }, 
        "Type": "A", 
        "Name": "scottstensland.com."
    }, 
    {
        "ResourceRecords": [
            {
                "Value": "ns-1238.awsdns-26.org."
            }, 
            {
                "Value": "ns-201.awsdns-25.com."
            }, 
            {
                "Value": "ns-969.awsdns-57.net."
            }, 
            {
                "Value": "ns-1823.awsdns-35.co.uk."
            }
        ], 
        "Type": "NS", 
        "Name": "scottstensland.com.", 
        "TTL": 172800
    }, 
    {
        "ResourceRecords": [
            {
                "Value": "ns-1238.awsdns-26.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"
            }
        ], 
        "Type": "SOA", 
        "Name": "scottstensland.com.", 
        "TTL": 900
    }
]
</code></pre>

<p>... in above notice value of </p>

<pre><code>"HostedZoneId": "Z35SXDOTRQ7X7K", 
</code></pre>

<p>which is the second similarly name token <strong><em>Do NOT use wrong Hosted Zone ID</em></strong></p>

<p>step 3 - put below into your change file aws_route53_type_A.json  <a href="https://oliverhelm.me/sys-admin/updating-aws-dns-records-from-cli" rel="nofollow noreferrer">(for syntax Doc see link mentioned in comment above)</a></p>

<pre><code>{
  "Comment": "Update record to reflect new DNSName of fresh deploy",
  "Changes": [
    {
      "Action": "UPSERT",
      "ResourceRecordSet": {
        "AliasTarget": {
            "HostedZoneId": "Z35SXDOTRQ7X7K", 
            "EvaluateTargetHealth": false, 
            "DNSName": "dualstack.a0b82c81f47d011e6b98a0a28439e7db-1867261689.us-east-1.elb.amazonaws.com."
        }, 
        "Type": "A", 
        "Name": "scottstensland.com."
      }
    }
  ]
}
</code></pre>

<p>To identify value for above field "DNSName" ... after the kubernetes app deploy on aws it responds with a LoadBalancer Ingress as shown in output of cli command :</p>

<pre><code>kubectl describe svc --namespace=ruptureofthemundaneplane
</code></pre>

<p>... as in </p>

<pre><code>LoadBalancer Ingress:   a0b82c81f47d011e6b98a0a28439e7db-1867261689.us-east-1.elb.amazonaws.com
</code></pre>

<p>... even though my goal is to execute a command line call I can do this manually by getting into the aws console browser ... pull up my domain on route53 ... </p>

<p><a href="https://i.stack.imgur.com/UIzqu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UIzqu.png" alt="Notice the green circle where the correct value of my LoadBalancer Ingress URL will auto appear in a self populating picklist (thanks aws)"></a> </p>

<p>...  In this browser picklist editable text box (circled in green) I noticed the URL gets magically prepended with :  dualstack.    Previously I was missing that magic string ...  so json key "DNSName" wants this </p>

<pre><code>dualstack.a0b82c81f47d011e6b98a0a28439e7db-1867261689.us-east-1.elb.amazonaws.com.
</code></pre>

<p>finally execute the change request</p>

<pre><code>aws route53 change-resource-record-sets --hosted-zone-id Z3II3949ZDMDXV --change-batch file://./aws_route53_type_A.json
</code></pre>

<p>... output</p>

<pre><code>{
    "ChangeInfo": {
        "Status": "PENDING", 
        "Comment": "Update record to reflect new DNSName of fresh deploy", 
        "SubmittedAt": "2016-07-13T14:53:02.789Z", 
        "Id": "/change/CFUX5R9XKGE1C"
    }
}
</code></pre>

<p>.... now to confirm change is live run this to show record</p>

<pre><code>aws route53  list-resource-record-sets  --hosted-zone-id Z3II3949ZDMDXV  
</code></pre>
