|
| 1 | +#!/usr/bin/python |
| 2 | +import time |
| 3 | +import requests |
| 4 | +import boto3 |
| 5 | + |
| 6 | +def parse_command_id(send_command_output): |
| 7 | + return send_command_output['Command']['CommandId'] |
| 8 | + |
| 9 | +def main(): |
| 10 | + ec2_client = boto3.client('ec2') |
| 11 | + ssm_client = boto3.client('ssm') |
| 12 | + |
| 13 | + # Get the list of instance IDs and their states |
| 14 | + instances_response = ec2_client.describe_instances() |
| 15 | + |
| 16 | + for reservation in instances_response['Reservations']: |
| 17 | + for instance in reservation['Instances']: |
| 18 | + state = instance['State']["Name"] |
| 19 | + instance_id = instance['InstanceId'] |
| 20 | + if state == 'running': |
| 21 | + ip = instance["PublicIpAddress"] |
| 22 | + instance_type = instance["InstanceType"] |
| 23 | + BASE_URL=f"http://{ip}:3000/" |
| 24 | + target = f"{BASE_URL}/" |
| 25 | + print(f"Starting command for instance: {instance_id} {target} {instance_type}") |
| 26 | + try: |
| 27 | + response = requests.get(target, timeout=8) |
| 28 | + print(f"got response: {instance_id} {target} {instance_type} {response.text}") |
| 29 | + |
| 30 | + target2 = f"{BASE_URL}/TINE-IntrospectorIsNotEliza/message" |
| 31 | + response2 = requests.post(target2,data={"text":"how are you","userId":"test","userName":"user"}, timeout=80) |
| 32 | + print(f"got response2: {instance_id} {target2} {instance_type} {response2.text} {response2.json()}") |
| 33 | + print(f"got response2: {instance_id} {target2} {instance_type} {response2.text}" ) |
| 34 | + except Exception as exp: |
| 35 | + print(f"got error: {instance_id} {target} {instance_type} {exp}") |
| 36 | + |
| 37 | + #curl -d "{'text':'fsdfsd'}" http://18.190.253.117:3000 |
| 38 | + |
| 39 | +if __name__ == "__main__": |
| 40 | + main() |
0 commit comments