-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecs.py
More file actions
36 lines (29 loc) · 1.14 KB
/
ecs.py
File metadata and controls
36 lines (29 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import boto3
def list_aws_regions():
# Initialize the EC2 client with the default region
ec2 = boto3.client('ec2')
# Retrieve all regions that work with EC2
response = ec2.describe_regions()
# Extract region names from the response
regions = [region['RegionName'] for region in response['Regions']]
return regions
def list_ecs_clusters(region):
try:
# Initialize an ECS client for the specified region
ecs = boto3.client('ecs', region_name=region)
# List all ECS clusters (returns a list of cluster ARNs)
ecs_clusters = ecs.list_clusters()
return ecs_clusters['clusterArns']
except Exception as e:
return None
# Print table head
print("| Region | ECS Cluster ARN |")
print("|--------------|---------------------------------------------|")
# Call the function to list ECS clusters in each AWS region
regions = list_aws_regions()
for region in regions:
ecs_clusters = list_ecs_clusters(region)
if ecs_clusters:
for cluster_arn in ecs_clusters:
# Print table row
print(f"| {region} | {cluster_arn} |")