Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EC2 Remote from Windows : ec2_connect.ps1 missing #6248

Open
ojacques opened this issue Dec 16, 2024 · 10 comments
Open

EC2 Remote from Windows : ec2_connect.ps1 missing #6248

ojacques opened this issue Dec 16, 2024 · 10 comments
Labels
bug We can reproduce the issue and confirmed it is a bug. platform:windows service:ec2

Comments

@ojacques
Copy link

Problem

When trying the new experimental feature to "connect to EC2 instance in a new Remote window" from Windows, the script ec2_connect.ps1 is missing.

image

Logs :

2024-12-16 13:36:48.386 [error] aws.ec2.openRemoteConnection: Error: Failed to update connect script [ConnectScriptUpdateFailed]
	 -> EntryNotFound (FileSystemError): Error: ENOENT: no such file or directory, open 'c:\Users\[redacted]\.vscode\extensions\amazonwebservices.aws-toolkit-vscode-3.39.0\resources\ec2_connect.ps1' [FileNotFound]

Steps to reproduce the issue

  1. Start VSCode on Windows, with AWS Toolkit 3.39
  2. Enable experimental feature "ec2RemoteConnect"
  3. Browse to an EC2 in AWS Toolkit explorer
  4. Click the button "connect to EC2 instance in a new Remote window"
  5. The error is shown

Expected behavior

I should be able to open a new VSCode window, connected to this remote EC2 through SSM.

System details (run AWS: About and/or Amazon Q: About)

  • OS: Windows 11
  • Visual Studio Code version: 1.96.0
  • AWS Toolkit version: 3.39.0
  • Amazon Q version: NA
@ojacques ojacques added the bug We can reproduce the issue and confirmed it is a bug. label Dec 16, 2024
@justinmk3
Copy link
Contributor

Connecting from Windows is not yet implemented. We plan to follow up on this.

@ojacques
Copy link
Author

Connecting from Windows is not yet implemented. We plan to follow up on this.

Thanks! So I should not expect being able to connect from WSL on Windows to a remote EC2 either? The error is different, but I'm leaving it here:

Connecting to Dev Environment requires the Remote SSH extension ('ms-vscode-remote.remote-ssh' of version >=0.74.0) to be installed and enabled.

despite the Remote SSH extension being installed (v 0.116.0).

@justinmk3
Copy link
Contributor

justinmk3 commented Dec 16, 2024

So I should not expect being able to connect from WSL on Windows to a remote EC2 either? The error is different, but I'm leaving it here:

If you started vscode from WSL and are running the WSL (Linux) version of vscode, it should work. If you are connecting to WSL from Windows, then that is a "remote" situation which isn't currently supported (it would require remote-ssh in the remote (WSL) vscode instance, plus AWS Toolkit would need to understand this and invoke vscode in the correct way, which currently is not supported).

despite the Remote SSH extension being installed (v 0.116.0).

Is it installed in the remote WSL environment (not your local desktop vscode code)?

@ojacques
Copy link
Author

If you started vscode from WSL

Yes, from WSL, running code .

and are running the WSL (Linux) version of vscode, it should work.

Indeed, no. VSCode is installed on Windows, with the remote extension, which I understand is not supported at the moment.

Feel free to close this issue as this is unsupported for now.

@jpinkney-aws jpinkney-aws marked this as a duplicate of #6493 Feb 4, 2025
@guteksan
Copy link

guteksan commented Feb 5, 2025

Connecting from Windows is not yet implemented. We plan to follow up on this.

Ok. Are there any plans to implement it? Is there much more work to be done aparat from translating the bash version of the 'ec2_connect' scritp to powershell?

@justinmk3
Copy link
Contributor

Is there much more work to be done aparat from translating the bash version of the 'ec2_connect' scritp to powershell?

That's pretty much it :) Patch welcome!

@guteksan
Copy link

Is there much more work to be done aparat from translating the bash version of the 'ec2_connect' scritp to powershell?

That's pretty much it :) Patch welcome!

I think there might be little more to it than that. I translated the shell script to ps1 using copilot, but that's not enough, and having little experience with this toolkit, I can't quickly fix it. Pretty please, provide a fix, if that's not a big problem on your side.

@nathanlisabio
Copy link

@guteksan if its not too much effort, can you drop what you have thus far? gonna give this a shot later

@jmikedupont2
Copy link

here is the ai generated version i am working on testing

#Requires -Version 5.1

# Usage:
#   When connecting to a dev environment
#   $env:AWS_REGION="…"; $env:AWS_SSM_CLI="…"; $env:STREAM_URL="…"; $env:TOKEN="…"; $env:LOG_FILE_LOCATION="…"; $env:DEBUG_LOG="…"; .\ec2_connect.ps1

# Exit on errors
$ErrorActionPreference = "Stop"

# Date command equivalent
function Get-DateString {
    return Get-Date -Format "yyyy/MM/dd HH:mm:ss"
}

function Write-Log {
    param (
        [Parameter(Mandatory=$true)]
        [string]$Message
    )
    "$(Get-DateString) $Message" | Out-File -FilePath $env:LOG_FILE_LOCATION -Append
}

function Test-RequiredNoLog {
    param (
        [string]$Name,
        [string]$Value
    )
    if ([string]::IsNullOrEmpty($Name) -or [string]::IsNullOrEmpty($Value)) {
        Write-Log "error: missing required arg: $Name"
        exit 1
    }
}

function Test-Required {
    param (
        [string]$Name,
        [string]$Value
    )
    Test-RequiredNoLog -Name $Name -Value $Value
    Write-Log "$Name=$Value"
}

function Start-EC2Session {
    param (
        [string]$AWSSSMCLI,
        [string]$AWSRegion,
        [string]$StreamURL,
        [string]$Token,
        [string]$SessionID
    )
    
    $jsonPayload = @{
        streamUrl = $StreamURL
        tokenValue = $Token
        sessionId = $SessionID
    } | ConvertTo-Json -Compress
    
    # Execute the SSM CLI command
    & $AWSSSMCLI $jsonPayload $AWSRegion "StartSession"
}

function Main {
    Write-Log "=============================================================================="
    
    Test-Required -Name "DEBUG_LOG" -Value $env:DEBUG_LOG
    Test-Required -Name "AWS_REGION" -Value $env:AWS_REGION
    
    Test-Required -Name "SESSION_ID" -Value $env:SESSION_ID
    Test-RequiredNoLog -Name "STREAM_URL" -Value $env:STREAM_URL
    Test-RequiredNoLog -Name "TOKEN" -Value $env:TOKEN

    # Only log file paths when debug level is enabled
    if ([int]$env:DEBUG_LOG -eq 1) {
        Test-Required -Name "AWS_SSM_CLI" -Value $env:AWS_SSM_CLI
        Test-Required -Name "LOG_FILE_LOCATION" -Value $env:LOG_FILE_LOCATION
    }
    else {
        Test-RequiredNoLog -Name "AWS_SSM_CLI" -Value $env:AWS_SSM_CLI
        Test-RequiredNoLog -Name "LOG_FILE_LOCATION" -Value $env:LOG_FILE_LOCATION
    }

    Start-EC2Session -AWSSSMCLI $env:AWS_SSM_CLI `
                    -AWSRegion $env:AWS_REGION `
                    -StreamURL $env:STREAM_URL `
                    -Token $env:TOKEN `
                    -SessionID $env:SESSION_ID
}

# Execute main function
Main

@nathanlisabio
Copy link

nathanlisabio commented Mar 7, 2025

some updates:

  1. just by using the above script (small modification to the input args), was able to get the terminal button to connect successfully
  2. however, using the connect using vscode method got me to a brand new error. If anyone has any hints, please drop:

2025-03-06 21:58:23.729 [error] aws.ec2.openRemoteConnection: Error: Unable to connect to target instance {the instance id redacted} on region us-east-1. Testing SSM connection to instance failed: Connection closed by UNKNOWN port 65535 [EC2SSMTestConnect] 2025-03-06 22:00:56.941 [info] telemetry: sent batch (size=19)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug We can reproduce the issue and confirmed it is a bug. platform:windows service:ec2
Projects
None yet
Development

No branches or pull requests

5 participants