krz/aws-summary-report
Automated AWS summary reports, straight to your inbox.
clone: git clone https://gitbay.org/krz/aws-summary-report.git
main: sections/cloudfront.py · raw
1# cloudfront.py
2import boto3
3from datetime import datetime, timedelta, timezone
4from tabulate import tabulate
5
6
7def get_section(config):
8 profile = config["aws"].get("profile")
9 session = boto3.Session(profile_name=profile if profile else None)
10 client = session.client("cloudfront")
11
12 now = datetime.now(timezone.utc)
13 cutoff = now - timedelta(days=2)
14
15 dists = client.list_distributions().get("DistributionList", {}).get("Items", [])
16 rows = []
17
18 for dist in dists:
19 last_mod = dist["LastModifiedTime"]
20 if last_mod >= cutoff:
21 rows.append(
22 [dist["Id"], dist["DomainName"], last_mod.strftime("%Y-%m-%d %H:%M")]
23 )
24
25 if not rows:
26 return "CloudFront Changes:\nNo distributions changed in the last 48h."
27
28 table = tabulate(
29 rows, headers=["ID", "Domain", "Last Modified"], tablefmt="simple_grid"
30 )
31 lines = [
32 "CloudFront Distribution Changes (Last 48h):",
33 f"[https://{config['aws'].get('region')}.console.aws.amazon.com/cloudfront/v4/home#/distributions]",
34 table,
35 ]
36
37 return "\n".join(lines)