@@ -14,6 +14,14 @@ $ErrorActionPreference = "Stop"
1414# Unblock-File -Path $HOME\.ssh\aws-ssm-ssh-proxy-command.ps1
1515#
1616
17+ $REGION_SEPARATOR = " --"
18+ $INSTANCE_ID_PATTERN = ' ^m?i-[0-9a-f]{8,17}$'
19+
20+ $instance_name = $args [0 ]
21+ $ssh_user = $args [1 ]
22+ $ssh_port = $args [2 ]
23+ $ssh_public_key_path = $args [3 ]
24+
1725function Get-InstanceId {
1826 param (
1927 [string ]$instanceName
@@ -24,12 +32,12 @@ function Get-InstanceId {
2432 return $instanceId
2533}
2634
27- $instance_name = $args [0 ]
28- $ssh_user = $args [1 ]
29- $ssh_port = $args [2 ]
30- $ssh_public_key_path = $args [3 ]
35+ $splitted_instance = $instance_name -split $REGION_SEPARATOR
36+ if ($splitted_instance.Length -gt 1 ) {
37+ $instance_name = $splitted_instance [0 ]
38+ $env: AWS_REGION = $splitted_instance [1 ]
39+ }
3140
32- $ec2InstanceIdPattern = ' ^m?i-[0-9a-f]{8,17}$'
3341if ($instance_name -match $ec2InstanceIdPattern ) {
3442 $instance_id = $instance_name
3543} else {
@@ -43,13 +51,6 @@ if ($instance_name -match $ec2InstanceIdPattern) {
4351 }
4452}
4553
46- $REGION_SEPARATOR = " --"
47- $splitted_instance = $instance_id -split $REGION_SEPARATOR
48- if ($splitted_instance.Length -gt 1 ) {
49- $instance_id = $splitted_instance [0 ]
50- $env: AWS_REGION = $splitted_instance [1 ]
51- }
52-
5354Write-Output " Add public key $ssh_public_key_path for $ssh_user at instance $instance_id for 10 seconds"
5455$ssh_public_key = (Get-Content $ssh_public_key_path | Select-Object - first 1 ) + ' ssm-session'
5556
0 commit comments