Skip to content

Instantly share code, notes, and snippets.

@broo0ose
Last active March 17, 2023 11:45
Show Gist options
  • Select an option

  • Save broo0ose/834ba9fc8bd8e99358fea361d2961bba to your computer and use it in GitHub Desktop.

Select an option

Save broo0ose/834ba9fc8bd8e99358fea361d2961bba to your computer and use it in GitHub Desktop.

Revisions

  1. broo0ose revised this gist Sep 17, 2021. No changes.
  2. broo0ose revised this gist Sep 17, 2021. No changes.
  3. broo0ose revised this gist Aug 24, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SessionManager.ps1
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # Creates a tunnel using AWS session manager to an AWS instance so that you can connect with a local client over the tunnel
    # Bruce Richardson 28/07/2021
    # https://github.com/broo0ose 24/08/2021
    # pre-reqs for this script
    # - AWS CLI environment on powershell
    # - the AWS Session Manager plugin https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html
  4. broo0ose revised this gist Aug 24, 2021. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions SessionManager.ps1
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,11 @@
    # Bruce Richardson 28/07/2021
    # pre-reqs for this script
    # - AWS CLI environment on powershell
    # - set up using 'aws configure sso' to the correct account and profile.
    # - logged in using 'aws login sso' Or however you connect to AWS, eg IAM account.
    # - the AWS Session Manager plugin https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html

    # - I use SSO to connect to AWS so I needed to use 'aws configure sso' to the correct account and profile.
    # - logged in using 'aws login sso' Or however you connect to AWS, eg IAM account.

    # - the instance must be set up to use AWS Session Manager, and you must have the rights to run the client connection eg. remote admin group.

    Clear-Host
    @@ -14,7 +16,7 @@ $target="i-whatever"
    $localport=54321
    $remoteport=3389
    $region="eu-west-1"
    $profile=""
    $profile="name_of_profile"

    # Check the values with the user

  5. broo0ose created this gist Aug 24, 2021.
    37 changes: 37 additions & 0 deletions SessionManager.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    # Creates a tunnel using AWS session manager to an AWS instance so that you can connect with a local client over the tunnel
    # Bruce Richardson 28/07/2021
    # pre-reqs for this script
    # - AWS CLI environment on powershell
    # - set up using 'aws configure sso' to the correct account and profile.
    # - logged in using 'aws login sso' Or however you connect to AWS, eg IAM account.
    # - the AWS Session Manager plugin https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html
    # - the instance must be set up to use AWS Session Manager, and you must have the rights to run the client connection eg. remote admin group.

    Clear-Host

    # set up some defaults
    $target="i-whatever"
    $localport=54321
    $remoteport=3389
    $region="eu-west-1"
    $profile=""

    # Check the values with the user

    $prompt = Read-Host "Enter the profile, default is" [$($profile)]""
    if (!$prompt -eq "") {$profile = $prompt}

    $prompt = Read-Host "Enter the region, default is" [$($region)]""
    if (!$prompt -eq "") {$region = $prompt}

    $prompt = Read-Host "enter the instance to connect to " [$($target)]""
    if (!$prompt -eq "") {$target = $prompt}

    $prompt = Read-Host "enter the remote port to connect to (e.g. RDP is 3389) " [$($remoteport)]""
    if (!$prompt -eq "") {$remoteport = $prompt}


    Write-Output "When the 'Waiting for connections' message comes up, connect your local client to 127.0.0.1:$localport"

    # Start the session manager to create a tunnel to the instance.
    aws ssm start-session --target $target --document-name AWS-StartPortForwardingSession --parameters "localPortNumber=$localport,portNumber=$remoteport" --region $region --profile $profile