Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions custom/bash/sleep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# Sleep script for StackGuardian templates

echo "Sleeping for 5 minutes..."
sleep 300
echo "Done sleeping!"
46 changes: 46 additions & 0 deletions custom/python/list_ec2_instances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from logging import error
import os
import time
import boto3


def check_aws_variables():
# Check if AWS_DEFAULT_REGION is set in the environment variables
if "AWS_DEFAULT_REGION" not in os.environ:
# If not, show error and exit with 1
error("AWS_DEFAULT_REGION is not set in the environment variables.")
exit(1)


def list_ec2_instances():
# Create an EC2 client
ec2 = boto3.client("ec2")

# Fetch instance details
response = ec2.describe_instances()

# Loop over instance details and format output
for reservation in response.get("Reservations", []):
for instance in reservation.get("Instances", []):
print(f"Instance ID: {instance.get('InstanceId')}")
print(f"Instance Type: {instance.get('InstanceType')}")
print(f"State: {instance.get('State', {}).get('Name')}")

if "Tags" in instance:
print("Tags:")
for tag in instance["Tags"]:
print(f" > {tag.get('Key')}: {tag.get('Value')}")

print("---")
# Sleep for 5 minutes (300 seconds) after each instance
print("Sleeping for 5 minutes...")
time.sleep(300)


def main():
check_aws_variables()
list_ec2_instances()


if __name__ == "__main__":
main()