0

Like we have python library BOTO3 which we can use to ssh into a linux based ec2 instance, but it looks like the same script does not work for a windows based ec2 instance. I used the python script in this question to connect to my windows How to SSH and run commands in EC2 using boto3? . But I am getting the below error :

[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

All my security group rules are compliant, I have RDP port open in incoming tab. Still getting this error. Is there a way in python to RDP into a windows ec2 instance ? Or any other programing language for that matter ?

Maurice
  • 11,482
  • 2
  • 25
  • 45
Kashyap Sharma
  • 109
  • 2
  • 10
  • What is it you're actually trying to achieve? Maybe you're looking for Powershell Remote... – Maurice Feb 10 '21 at 15:06
  • @maurice I am looking to execute some sql scripts on my windows bases ec2 instance, currently we RDP into the jumphost, and then open the SSMS tool, and then connect to the required DB and execute the script. I wanted to automate this, for that I was looking to establish an RDP conn via a script and then execute those sql queries. All at one go. – Kashyap Sharma Feb 10 '21 at 15:22
  • 1
    RDP is a GUI based solution whereas SSH is a CLI based solution. GUI based solutions are much harder to automate and even more difficult to do that in a robust way. Depending on how generic this is, you could create a Systems Manager Automation Document and execute that via the AWS API, that way you don't have to open a port to the outside. Another solution would be using Powershell Remoting, which allows you to create a shell-like session using Powershell. – Maurice Feb 10 '21 at 15:25
  • 1
    This is indeed quite generic . Looks like system manager is the way out for what I need. Powershell is also an option but I don't have administrator access. Will have to explore aws system manager. Thank you Maurice – Kashyap Sharma Feb 10 '21 at 15:57

1 Answers1

1

To summarize what we talked about in the comments.

Your goal is to run SQL scripts against a database from an EC2 windows instance and you want to trigger this via Python.

Your suggested solution of using RDP is problematic, because in contrast to SSH, RDP is a GUI-driven protocol, it will essentially send color values for pixels to you, which is hard to interact with. The equivalent to an SSH connection is more or less PowerShell Remoting, which would require you to open a port, that is accessible from your python script.

A solution that doesn't require making the server accessible from the outside would be using Systems Manager automation. You can create an automation document to run a PowerShell script on the instance for example and trigger that via the API (ssm:StartAutomationExecution).

Maurice
  • 11,482
  • 2
  • 25
  • 45