Skip to content

Commit

Permalink
hold for jump
Browse files Browse the repository at this point in the history
  • Loading branch information
mike dupont committed Jan 22, 2025
1 parent 2ec61e2 commit c39f65a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ssh-ssm.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#!/usr/bin/python
import time

import json
import boto3
#from dateutil import tz


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

def fwd(instance):
# https://aws.amazon.com/blogs/aws/new-port-forwarding-using-aws-system-manager-sessions-manager/
#INSTANCE_ID=$(aws ec2 describe-instances --filter "Name=tag:Name,Values=CodeStack/NewsBlogInstance" --query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]" --output text)
# create the port forwarding tunnel
prms = {
"portNumber":["22"],
"localPortNumber":["2222"]
}
prms_jsn = json.dumps(prms)
print(f"""aws ssm start-session --target {instance} --document-name AWS-StartPortForwardingSession --parameters '{prms_jsn}'""")

def main():
ec2_client = boto3.client('ec2')
ssm_client = boto3.client('ssm')
Expand All @@ -26,8 +37,9 @@ def main():
instance_id = instance['InstanceId']
state = instance['State']['Name']
if state == 'running':
print(f"Starting command for instance: {instance_id}")
print(f"aws ssm start-session --target {instance_id}")
#print(f"Starting command for instance: {instance_id}")
#print(f"aws ssm start-session --target {instance_id}")
fwd(instance_id)

if __name__ == "__main__":
main()

0 comments on commit c39f65a

Please sign in to comment.