title: If I run the script from a command line (as root), it works. If it runs at a boot time, it fails
body: <p>I have a shell script that I want to run at boot time. In this script I'm using aws cli to update my IP to route53 record set, if I run the script from a command line (as root user), it works. If it runs at a boot time, it fails. I configured aws credential for root user already.
  My update-route53-record.sh</p>
  
  <pre><code>#!/bin/bash
  
  DOMAIN_NAME="mydomain.com"
  HOSTED_ZONE_ID="Z1986XXXXXXXXX"
  
  main(){
      UPDATED_IP_LIST=$(updated_ip_list)    
      update_route53_record "$UPDATED_IP_LIST"
  }
  
  # Get IP List of $DOMAIN_NAME from route53
  get_ip_list(){
      RECORD_SET_JSON=$( aws route53 list-resource-record-sets --hosted-zone-id Z1986QIYBBYSUJ --query "ResourceRecordSets[?Name == '$DOMAIN_NAME.']")
  
      #Remove the first and last character in string  to convert json array to json object
      RECORD_SET_JSON=${RECORD_SET_JSON:1:-1}
  
      # Need to install jq to parse json http://xmodulo.com/how-to-parse-json-string-via-command-line-on-linux.html
      # Get value of ResourceRecords
      RECORD_SET_JSON=$( echo $RECORD_SET_JSON | jq -r '.ResourceRecords' )
  
      echo $RECORD_SET_JSON
  }
  
  updated_ip_list(){
      # Get public IP of running instance
      IP=$( curl http://169.254.169.254/latest/meta-data/public-ipv4 )
      # IP="192.168.10.1"
  
      # Get IP list from Route53 by invoking get_ip_list
      IP_LIST=$(get_ip_list)    
  
      # Get length of json array
      LENGTH=$(echo $IP_LIST | jq '. | length')
  
      # Add one element to last array
      IP_LIST=$(echo $IP_LIST | jq '.['$LENGTH'].Value |= .+ '\"$IP\"'')
  
      echo $IP_LIST
  }
  
  update_route53_record(){   
      JSON_REQUEST='{
                "Comment": "Update the A record set",
                "Changes": [
                  {
                    "Action": "UPSERT",
                    "ResourceRecordSet": {
                      "Name": '\"$DOMAIN_NAME\"',
                      "Type": "A",
                      "TTL": 300,
                      "ResourceRecords": '$1'
                    }
                  }
                ]
              }'
      #echo $JSON_REQUEST
      #echo "Calling API..."
      aws route53 change-resource-record-sets  --hosted-zone-id "$HOSTED_ZONE_ID" --change-batch "$JSON_REQUEST"
  
      # write to log file
      echo "aws route53 change-resource-record-sets  --hosted-zone-id \"$HOSTED_ZONE_ID\" --change-batch \"$JSON_REQUEST\"" | sudo tee /var/log/update-route53.log
  }
  main
  exit 0
  </code></pre>
  
  <p>I install my script runs at boot time</p>
  
  <pre><code>sudo cp update-route53-record.sh /etc/init.d
  sudo chmod +x /etc/init.d/update-route53-record.sh
  sudo update-rc.d update-route53-record.sh defaults 98 02
  </code></pre>
  
  <p>But if I run the script from a command line (as root), it works. If it runs at a boot time, it fails. I configured aws credential for root user already.
  Could you please help?</p>