aws / aws-tools-for-powershell

The AWS Tools for PowerShell lets developers and administrators manage their AWS services from the PowerShell scripting environment.
Apache License 2.0
235 stars 77 forks source link

Support for interactive Start-SSMSession #283

Open iancward opened 1 year ago

iancward commented 1 year ago

Describe the feature

I would like to be able to use Start-SSMSession from PowerShell, just like I can with the AWS CLI

Use Case

Since I'm on a Windows machine, I'd prefer to use the native tools instead of having to install (and keep updated) the AWS CLI. I also like that AWS Tools for PowerShell is modular, so I can install only the modules I need in order to get done what I need.

Proposed Solution

AWS Tools for PowerShell would need to call the session-manager-plugin with the appropriate arguments.

Other Information

No response

Acknowledgements

AWS Tools for PowerShell version used

AWS.Tools.SimpleSystemsManagement 4.1.13

PowerShell version used

7.2.6

Operating System and version

Windows 10

ghost commented 1 year ago

Hi,

I'm looking to execute the following for RDP:

Start-SSMSession `
    -DocumentName AWS-StartPortForwardingSession `
    -Parameter @{ "portNumber" = "3389"; "localPortNumber" = "56789" } `
    -Target "i-xxxxxxxxx"

Is this something that would be covered by this request or is it supposed to be possible already? I wonder if I can use this thread to ask what the use of the current PS implementation is?

Thanks in advance,

Adam

ashishdhingra commented 1 year ago

@iancward Thanks for submitting feature request. All PowerShell CmdLets execute the AWS service command and return the results to the end user, in this case Start-SSMSession returns session StartSessionResponse. Also, having dependency on external program is not feasible (It has to assume that AWS CLI is installed with the session manager plugin configured). Session manager plugin is exclusive to AWS CLI and aws ssm start-session could have been implemented with custom implementation to interface with the plugin.

partdavid commented 3 months ago

The documentation for this cmdlet says:

Initiates a connection to a target (for example, a managed node) for a Session Manager session. Returns a URL and token that can be used to open a WebSocket connection for sending input and receiving outputs. Amazon Web Services CLI usage: start-session is an interactive command that requires the Session Manager plugin to be installed on the client machine making the call. For information, see Install the Session Manager plugin for the Amazon Web Services CLI in the Amazon Web Services Systems Manager User Guide. Amazon Web Services Tools for PowerShell usage: Start-SSMSession isn't currently supported by Amazon Web Services Tools for PowerShell on Windows local machines.

What are you supposed to do with the StartSessionResponse? I'm not on Windows and I have the session manager plugin installed--the documentation is a little confused and seems lifted from the AWS CLI, but it kind of implies to me that if I'm not on Windows and I do have the plugin installed I should be able to enter my session this way. If that's not the intention, could it indicate what you're supposed to do with the StartSessionResponse to actually connect to it?

trevorstr commented 3 months ago

I'm trying to use ESC exec to get an interactive shell into a container running on AWS Fargate. It works fine with the AWS CLI, but I would rather use the AWS Tools for PowerShell to get an interactive shell into my remote container.

# Launch an interactive process in Fargate container
$Params = @{
  Cluster = 'trevor-fargate'
  Container = 'easyproxy'
  Command = '/opt/microsoft/powershell/7/pwsh'
  Interactive = $true
  Task = '4529facf1b9d4aefb6c3f228ffc81baa'
}}
$s = Invoke-ECSCommand @Params

# Try to get interactive session
Resume-SSMSession -SessionId $s.Session.SessionId

The Resume-SSMSession command seems like it should launch me into an interactive shell, but all it does is return the websocket URL and SSM session ID.

Wool3673 commented 1 month ago

I'm confused about when this cmd-let can be used when the document states "Amazon Web Services Tools for PowerShell usage: Start-SSMSession isn't currently supported by Amazon Web Services Tools for PowerShell on Windows local machines".

https://docs.aws.amazon.com/powershell/latest/reference/items/Start-SSMSession.html