PowerShell Powered DDNS with AWS

I wanted to write a script to update DNS records in AWS to make my own Dynamic DNS solution. I got the idea from some scripts I’d seen online, but really didn’t want to deal with all the Python.
Instead, I found that you can get AWS PowerShell cmdlets to do the same thing. Yay!

# Install AWS PowerShell tools 
# https://docs.aws.amazon.com/powershell/latest/userguide/pstools-getting-set-up.html
# Install-Module $module -Scope CurrentUser 
# Scope required if installing without administrative rights

Import-Module AWSPowerShell

# AWS Information
$AccessID="**Access ID Here**"
$SecureID="**Secure ID Here**"
$ZoneID="**Zone ID Here**"
$Recordset="**FQDN to be updated Here**"
$TTL=100
$Type="A"

# Determine public IP address
$IP=(Resolve-DnsName -Name myip.opendns.com -Server resolver1.opendns.com).IPAddress

# Get the current IP address value of the record
$RecordData=(Test-R53DNSAnswer -AccessKey $AccessID -SecretKey $SecureID -HostedZoneId $ZoneID -RecordName $Recordset -RecordType $type).RecordData


If ($IP -eq $RecordData) # Check to see if the IP value of the record is correct or needs to be updated
    {
    "Record data correct, no action required"
    }
Else
    {
    # Set parameters to delete the existng record
    $Delete = New-Object Amazon.Route53.Model.Change
    $Delete.Action = "DELETE"
    $Delete.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet
    $Delete.ResourceRecordSet.Name = $Recordset
    $Delete.ResourceRecordSet.Type = $Type
    $Delete.ResourceRecordSet.TTL = $TTL
    $Delete.ResourceRecordSet.ResourceRecords.Add(@{Value=$IP})

    # Set parameters to create a new record with the correct IP address
    $Create = New-Object Amazon.Route53.Model.Change
    $Create.Action = "CREATE"
    $Create.ResourceRecordSet = New-Object Amazon.Route53.Model.ResourceRecordSet
    $Create.ResourceRecordSet.Name = $IP
    $Create.ResourceRecordSet.Type = $Type
    $Create.ResourceRecordSet.TTL = $TTL
    $Create.ResourceRecordSet.ResourceRecords.Add(@{Value=$IP})

    # Execute the deletion and creation of the record
    Edit-R53ResourceRecordSet -AccessKey $AccessID -SecretKey $SecureID -HostedZoneId $ZoneID -ChangeBatch_Change $Delete,$Create
    }