ps/Modules/Alkami.PowerShell.Common/Public/Get-CurrentInstanceRegion.ps1
2023-05-30 22:51:22 -07:00

27 lines
704 B
PowerShell

function Get-CurrentInstanceRegion {
<#
.SYNOPSIS
Uses IMDS metadata to retrieve the instance region.
#>
[CmdletBinding()]
[OutputType([System.String])]
param()
$logLead = (Get-LogLeadName)
$endpoint = "/dynamic/instance-identity/document"
if (!(Test-IsAws)) {
Write-Warning "$logLead : This Function Can Only Be Called on an AWS Server"
return
}
Write-Verbose "$logLead : Getting Current Instance"
$identityDocumentJson = (Get-InstanceMetadata -Endpoint $endpoint)
$region = ($identityDocumentJson | ConvertFrom-Json | Select-Object Region).Region
Write-Verbose "$logLead : Region Read as $region"
return $region
}