since this turned out to be more difficult than I'd thought, posting it here.
$dbserver_instance = (Get-EC2Instance -Filter @{Name="tag:Name";Value="yourservernamehere"} -Region us-east-1).Instances
get-ec2volume -filter @{Name="attachment.instance-id";value="$($dbserver_instance.instanceid)"} -region us-east-1
The tricky part is the tag:Name, which isn't obvious. Also odd, if you just run the get-ec2volume with the tag:name and value, you get the exact same message as if you ran get-ec2instance! I don't pretend to understand that.
Tuesday, June 26, 2018
Wednesday, June 6, 2018
[AWS RDS] Sending an email when there's a new version of RDS available
Something I needed recently. Difficulty level: Get-RDSPendingMaintenanceAction ONLY returns info when there's something to be done. If you're current, there's no way to find out what it looks like.
This will email you a HTML-formatted table with the details of each pending maintenance action for every instance in a region.
This will email you a HTML-formatted table with the details of each pending maintenance action for every instance in a region.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Remove-Variable -Name * -ErrorAction SilentlyContinue | |
import-module awspowershell | |
$myaccesskey = "youraccesskey" | |
$mysecretkey = "yoursecretkey" | |
$myregion = "yourregion" | |
$myemail = "youremailaddress" | |
$mysmtp = "smtp.yourcompany.com" | |
set-awscredentials -accesskey $myaccesskey -secretkey $mysecretkey | |
$now = get-date | |
$upgrade_info = Get-RDSPendingMaintenanceAction -Region $myregion | |
# Taking the results and parsing out the info for each instance | |
$Parsed_Results = $upgrade_info | select @{Label='ResourceIdentifier';Expression={$_.ResourceIdentifier} | |
}, @{Label='Action';Expression={$_.PendingMaintenanceActionDetails.Action} | |
}, @{Label='Description';Expression={$_.PendingMaintenanceActionDetails.Description} | |
}, @{Label='AutoAppliedAfterDate';Expression={$_.PendingMaintenanceActionDetails.AutoAppliedAfterDate} | |
}, @{Label='CurrentApplyDate';Expression={$_.PendingMaintenanceActionDetails.CurrentApplyDate} | |
}, @{Label='ForcedApplyDate';Expression={$_.PendingMaintenanceActionDetails.ForcedApplyDate} | |
}, @{Label='OptInStatus';Expression={$_.PendingMaintenanceActionDetails.OptInStatus} | |
} | |
# Making an HTML table | |
# https://jamesdatatechq.wordpress.com/2014/12/23/how-to-create-an-html-table-from-powershell/ | |
$Style = " | |
<style> | |
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;} | |
TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;} | |
TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;} | |
</style> | |
" | |
#Convert the parsed info to a table | |
$error_table = $Parsed_Results| ConvertTo-HTML -AS Table -Fragment -PreContent "<h2>Aurora Updates as of $now</h2>"|Out-String | |
#Save the HTML Web Page with the table style | |
[string]$email_table = (ConvertTo-HTML -head $Style -PostContent $error_table) | |
# Now send the mail | |
if ($upgrade_info){ | |
#Send email to $myemail. SMTP is a CNAME to the corporate SMTP server we use. | |
Send-MailMessage -smtpserver $mysmtp ` | |
-To $myemail ` | |
-From "My_AWS_Account_Do_Not_Reply <Dev@Null.Com>" ` | |
-Subject "[AWS] Aurora updates available - time to test and mark for upgrades if good. $now" ` | |
-body $email_table -BodyAsHtml | |
} |
Subscribe to:
Posts (Atom)