Created
June 11, 2022 02:54
-
-
Save sudheerchamarthi/a2e6e6f966a36216d0ec404a3f2b9c6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
s3_client = boto3.client('s3') | |
ec2_client = boto3.client('ec2', region_name="us-east-1") | |
import pprint | |
# Use this website for Json - https://jsoneditoronline.org/ | |
# s3_response = s3_client.create_bucket( | |
# Bucket='mys3bucket-tyuihgfdsrtyuikjhabc', | |
# ) | |
# | |
# if s3_response["ResponseMetadata"]["HTTPStatusCode"] == "200": | |
# print("S3 bucket create with name" + s3_response["Location"]) | |
# print("Date"+ s3_response["ResponseMetadata"]["HTTPHeaders"]["date"]) | |
# else: | |
# print("Creation Failed") | |
ec2_response = ec2_client.describe_instances() | |
for instance in ec2_response["Reservations"]: | |
if instance["Instances"][0]["InstanceType"] == "t2.micro": | |
#print("Your Instance type is:"+ instance["Instances"][0]["InstanceType"]) | |
print("Found Instance with t2.micro: "+ instance["Instances"][0]["InstanceId"]) | |
if instance["Instances"][0]["State"]["Name"] == "running": | |
stop_response = ec2_client.stop_instances(InstanceIds=[instance["Instances"][0]["InstanceId"],],Force=True) | |
pprint.print(stop_response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment