@@ -14,6 +14,14 @@ $ErrorActionPreference = "Stop"
14
14
# Unblock-File -Path $HOME\.ssh\aws-ssm-ssh-proxy-command.ps1
15
15
#
16
16
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
+
17
25
function Get-InstanceId {
18
26
param (
19
27
[string ]$instanceName
@@ -24,12 +32,12 @@ function Get-InstanceId {
24
32
return $instanceId
25
33
}
26
34
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
+ }
31
40
32
- $ec2InstanceIdPattern = ' ^m?i-[0-9a-f]{8,17}$'
33
41
if ($instance_name -match $ec2InstanceIdPattern ) {
34
42
$instance_id = $instance_name
35
43
} else {
@@ -43,13 +51,6 @@ if ($instance_name -match $ec2InstanceIdPattern) {
43
51
}
44
52
}
45
53
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
-
53
54
Write-Output " Add public key $ssh_public_key_path for $ssh_user at instance $instance_id for 10 seconds"
54
55
$ssh_public_key = (Get-Content $ssh_public_key_path | Select-Object - first 1 ) + ' ssm-session'
55
56
0 commit comments