Skip to content

Commit

Permalink
Update AWS EC2 SSM (Python).rdfe
Browse files Browse the repository at this point in the history
add a missing comma, and a couple of unescaped double quotes
  • Loading branch information
chrisgala committed Jul 24, 2023
1 parent 549825e commit 6771512
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"Value": "us-east-1"
}
],
"ScriptInterpreter": "python"
"Script": "import subprocess\nimport json\n\ndef get_instances(region = \"\"):\n\tcmd = \"aws ssm describe-instance-information --output json\"\n\n\tif region != \"\":\n\t\tcmd += \" --region \" + region\n\n\taws = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)\n\t(response_json, err) = aws.communicate()\n\texit_code = aws.wait()\n\n\tresponse = json.loads(response_json)\n\n\tconnections = [ ]\n\n\tfor instance in response.get(\"InstanceInformationList\", None):\n\t\tinstance_id = instance.get(\"InstanceId", \"\")\n\t\tplatform = instance.get(\"PlatformType\", \"\")\n\n\t\tis_windows = platform.lower() == \"windows\"\n\n\t\tcomputer_name = instance.get(\"ComputerName\", \"\")\n\t\tprivate_ip_address = instance.get(\"IPAddress\", \"\")\n\n\t\tname = instance_id\n\n\t\tconnection = { }\n\t\tif not is_windows:\n\t\t\tconnection[\"Type\"] = \"TerminalConnection\"\n\t\t\tconnection[\"TerminalConnectionType\"] = \"CustomTerminal\"\n\t\telse:\n\t\t\tconnection[\"Type\"] = \"RemoteDesktopConnection\"\n\n\t\tconnection[\"ID\"] = instance_id\n\t\tconnection[\"Name\"] = computer_name\n\t\tconnection[\"ComputerName\"] = computer_name\n\n\t\tconnection[\"CustomCommand\"] = f\"aws ssm start-session --target {instance_id}"\t\t\n\t\t\n\t\t# Run inside login shell so your credentials are accessible (either key pair or SSO token)\n\t\tconnection[\"Properties\"] = {}\n\t\tconnection[\"Properties\"][\"RunInsideLoginShell\"] = True\n\t\t\n\t\t\n\t\tconnections.append(connection)\n\n\tstore = {\n\t\t\"Objects\": connections\n\t}\n\n\tstore_json = json.dumps(store)\n\n\treturn store_json\n\t\nprint(get_instances(\"$CustomProperty.Region$\"))\n"
"ScriptInterpreter": "python",
"Script": "import subprocess\nimport json\n\ndef get_instances(region = \"\"):\n\tcmd = \"aws ssm describe-instance-information --output json\"\n\n\tif region != \"\":\n\t\tcmd += \" --region \" + region\n\n\taws = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)\n\t(response_json, err) = aws.communicate()\n\texit_code = aws.wait()\n\n\tresponse = json.loads(response_json)\n\n\tconnections = [ ]\n\n\tfor instance in response.get(\"InstanceInformationList\", None):\n\t\tinstance_id = instance.get(\"InstanceId\", \"\")\n\t\tplatform = instance.get(\"PlatformType\", \"\")\n\n\t\tis_windows = platform.lower() == \"windows\"\n\n\t\tcomputer_name = instance.get(\"ComputerName\", \"\")\n\t\tprivate_ip_address = instance.get(\"IPAddress\", \"\")\n\n\t\tname = instance_id\n\n\t\tconnection = { }\n\t\tif not is_windows:\n\t\t\tconnection[\"Type\"] = \"TerminalConnection\"\n\t\t\tconnection[\"TerminalConnectionType\"] = \"CustomTerminal\"\n\t\telse:\n\t\t\tconnection[\"Type\"] = \"RemoteDesktopConnection\"\n\n\t\tconnection[\"ID\"] = instance_id\n\t\tconnection[\"Name\"] = computer_name\n\t\tconnection[\"ComputerName\"] = computer_name\n\n\t\tconnection[\"CustomCommand\"] = f\"aws ssm start-session --target {instance_id}\"\t\t\n\t\t\n\t\t\n\t\tconnection[\"Properties\"] = {}\n\t\tconnection[\"Properties\"][\"RunInsideLoginShell\"] = True\n\t\t\n\t\t\n\t\tconnections.append(connection)\n\n\tstore = {\n\t\t\"Objects\": connections\n\t}\n\n\tstore_json = json.dumps(store)\n\n\treturn store_json\n\t\nprint(get_instances(\"$CustomProperty.Region$\"))\n"
}
]
}

0 comments on commit 6771512

Please sign in to comment.