Skip to content

Commit c39f65a

Browse files
author
mike dupont
committed
hold for jump
1 parent 2ec61e2 commit c39f65a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

ssh-ssm.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
#!/usr/bin/python
22
import time
3-
3+
import json
44
import boto3
55
#from dateutil import tz
66

77

88
def parse_command_id(send_command_output):
99
return send_command_output['Command']['CommandId']
1010

11+
def fwd(instance):
12+
# https://aws.amazon.com/blogs/aws/new-port-forwarding-using-aws-system-manager-sessions-manager/
13+
#INSTANCE_ID=$(aws ec2 describe-instances --filter "Name=tag:Name,Values=CodeStack/NewsBlogInstance" --query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]" --output text)
14+
# create the port forwarding tunnel
15+
prms = {
16+
"portNumber":["22"],
17+
"localPortNumber":["2222"]
18+
}
19+
prms_jsn = json.dumps(prms)
20+
print(f"""aws ssm start-session --target {instance} --document-name AWS-StartPortForwardingSession --parameters '{prms_jsn}'""")
21+
1122
def main():
1223
ec2_client = boto3.client('ec2')
1324
ssm_client = boto3.client('ssm')
@@ -26,8 +37,9 @@ def main():
2637
instance_id = instance['InstanceId']
2738
state = instance['State']['Name']
2839
if state == 'running':
29-
print(f"Starting command for instance: {instance_id}")
30-
print(f"aws ssm start-session --target {instance_id}")
40+
#print(f"Starting command for instance: {instance_id}")
41+
#print(f"aws ssm start-session --target {instance_id}")
42+
fwd(instance_id)
3143

3244
if __name__ == "__main__":
3345
main()

0 commit comments

Comments
 (0)