-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
157 lines (135 loc) · 4.49 KB
/
cli.py
File metadata and controls
157 lines (135 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import argparse
def build_ssm_parser():
parser = argparse.ArgumentParser(
description="🛠️ ssm-cli: Simplified AWS SSM EC2 interaction",
formatter_class=argparse.RawTextHelpFormatter,
epilog="""Examples:
ssm.py send-command -p myprofile -i i-123456 -c "uptime"
ssm.py port-forward -p myprofile -i web-server -P 8080:80
ssm.py port-forward-remote -p myprofile -i db-server -P 3306:3306 -d 127.0.0.1
ssm.py ssh -p myprofile -i web-server
ssm.py scp-to -p myprofile -i web-server -lp /local/file.txt -rp /remote/file.txt
ssm.py scp-from -p myprofile -i web-server -lp /local/file.txt -rp /remote/file.txt
"""
)
parser.add_argument(
"command",
metavar="COMMAND",
help="Available commands:\n"
" send-command Run a shell command on an instance\n"
" port-forward Start local port forwarding to an instance\n"
" port-forward-remote Forward a port from the instance to another destination\n"
" ssh Open an SSH session to an instance\n"
" scp-to Transfer a file to an instance\n"
" scp-from Transfer a file from an instance\n"
"\nIf omitted, opens an interactive shell via SSM.",
choices=["send-command", "port-forward", "port-forward-remote", "ssh", "scp-to", "scp-from"],
nargs="?",
default=None
)
parser.add_argument(
"-i", "--instances",
help="EC2 instance ID(s) or Name(s) (optional if you want to pick manually)",
nargs="+",
default=[],
required=False
)
parser.add_argument(
"-p", "--profile",
help="AWS named profile to use (required)",
required=True
)
parser.add_argument(
"-P", "--port",
help="Port mapping for forwarding, format: LOCAL:REMOTE (e.g. 8080:80)",
required=False
)
parser.add_argument(
"-d", "--destination",
help="Destination IP or hostname for remote port-forwarding (e.g. 127.0.0.1)",
required=False
)
parser.add_argument(
"-c", "--shell_comand",
help="Shell command to send to the instance (e.g. 'uptime')",
required=False
)
parser.add_argument(
"-r", "--region",
help="AWS region to use (defaults to profile's region)",
required=False
)
parser.add_argument(
"-k", "--key",
help="Path to the SSH private key file",
required=False
)
parser.add_argument(
"-u", "--user",
help="SSH username (defaults to 'ubuntu')",
required=False,
default="ubuntu"
)
parser.add_argument(
"-lp", "--local-path",
help="Local file path for SCP operations",
required=False
)
parser.add_argument(
"-rp", "--remote-path",
help="Remote file path for SCP operations",
required=False
)
return parser
def build_ssmc_parser():
parser = argparse.ArgumentParser(
description="🛠️ ssmc: Simplified AWS SSM ECS Container interaction",
formatter_class=argparse.RawTextHelpFormatter,
epilog="""Examples:
ssmc -p myprofile -c my-cluster -s my-service
ssmc -p myprofile -c my-cluster
ssmc port-forward -p myprofile -c my-cluster -s my-service -P 9999:9000
"""
)
parser.add_argument(
"command",
metavar="COMMAND",
help="Available commands:\n"
" port-forward Start port forwarding to a container\n"
"\nIf omitted, opens an interactive shell via SSM.",
choices=["port-forward"],
nargs="?",
default=None
)
parser.add_argument(
"-c", "--cluster",
help="ECS cluster name",
required=False
)
parser.add_argument(
"-s", "--service",
help="ECS service name (optional)",
required=False
)
parser.add_argument(
"-p", "--profile",
help="AWS named profile to use (required)",
required=True
)
parser.add_argument(
"-P", "--port",
help="Port mapping for forwarding, format: LOCAL:REMOTE (e.g. 9000:9000)",
required=False
)
parser.add_argument(
"--shell",
help="Shell to use in the container (default: bash)",
default="bash",
required=False
)
parser.add_argument(
"-r", "--region",
help="AWS region to use (defaults to profile's region)",
required=False
)
return parser