blob: df161e6f933ba2d7143998c6034418fc13308c8a (
plain) (
blame)
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
37
|
# cloudfront.py
import boto3
from datetime import datetime, timedelta, timezone
from tabulate import tabulate
def get_section(config):
profile = config["aws"].get("profile")
session = boto3.Session(profile_name=profile if profile else None)
client = session.client("cloudfront")
now = datetime.now(timezone.utc)
cutoff = now - timedelta(days=2)
dists = client.list_distributions().get("DistributionList", {}).get("Items", [])
rows = []
for dist in dists:
last_mod = dist["LastModifiedTime"]
if last_mod >= cutoff:
rows.append(
[dist["Id"], dist["DomainName"], last_mod.strftime("%Y-%m-%d %H:%M")]
)
if not rows:
return "CloudFront Changes:\nNo distributions changed in the last 48h."
table = tabulate(
rows, headers=["ID", "Domain", "Last Modified"], tablefmt="simple_grid"
)
lines = [
"CloudFront Distribution Changes (Last 48h):",
f"[https://{config['aws'].get('region')}.console.aws.amazon.com/cloudfront/v4/home#/distributions]",
table,
]
return "\n".join(lines)
|