agent: |
x282DP81FtfODlzMcvhpList All AWS CloudFront Distributions
List All AWS CloudFront Distributions
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
This task retrieves all content delivery networks (CDNs) set up in an AWS account via CloudFront. Each distribution represents a CDN configuration, providing insights into its ID, domain name, and other settings. This overview aids in efficiently managing and monitoring content delivery.
inputs
outputs
import boto3
creds = _get_creds(cred_label)['creds']
access_key = creds['username']
secret_key = creds['password']
# Initialize the CloudFront client
client = boto3.client('cloudfront',aws_access_key_id=access_key,aws_secret_access_key=secret_key)
try:
# Use a paginator for the list_distributions call
paginator = client.get_paginator('list_distributions')
all_distributions = []
# Iterate over each page of results
for page in paginator.paginate():
# Check if 'Items' key exists in the current page
distributions_on_page = page.get('DistributionList', {}).get('Items', [])
# Extend the all_distributions list with IDs from the current page
all_distributions.extend([dist['Id'] for dist in distributions_on_page])
# Check if there are any distributions and print appropriate messages
if all_distributions:
print(f"Found {len(all_distributions)} CloudFront distributions. Here are their IDs:")
for dist_id in all_distributions:
print(dist_id)
else:
print("No CloudFront distributions found.")
except client.exceptions.NoSuchDistribution as e:
print("Error: No such distribution found.")
print(f"Details: {str(e)}")
except client.exceptions.AccessDenied as e:
print("Error: Access denied. Make sure you have the appropriate permissions.")
print(f"Details: {str(e)}")
except Exception as e:
print("An unexpected error occurred while fetching the CloudFront distributions.")
print(f"Details: {str(e)}")
copied