private/start/Start-RemoteProxySessionInternal.ps1
function Start-RemoteProxySessionInternal { [CmdletBinding(PositionalBinding = $false)] param( [Parameter(Mandatory = $false)] [string] $ProfileName, [Parameter(Mandatory = $false)] [string] $Region ) Set-Region -Region $Region Set-Profile -ProfileName $ProfileName Write-ProgramHeader $awsProfile = Get-ConnectionProfile Write-ConnectionProfile -AwsProfile $awsProfile $ec2Instances = Get-Instance Write-Instance -Instances $ec2Instances $instanceId = Read-UserInstanceSelection -Ec2Instances $ec2Instances if (-not $instanceId) { return } try { $localPort = Get-EphemeralPort $session = Start-PortForwardingSessionToRemoteHost -InstanceId $instanceId -LocalPort $localPort -RemoteHost 'rds.amazonaws.com' -RemotePort 1521 $ssmProcess = Start-SessionManagerPlugin -Session $session -Region $awsProfile.Region while (-not $ssmProcess.HasExited) { Start-Sleep -Milliseconds 50 } } finally { Stop-SessionManagerPlugin -Process $ssmProcess Stop-PortForwardingSession -SessionId $session.Response.SessionId } } |