agent: |
ed86wPL2sDzC5dd22dCGList all AWS S3 buckets across all regions.
List all AWS S3 buckets across all regions.
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
The script lists all AWS S3 buckets using the provided AWS credentials.
inputs
outputs
import boto3
# Retrieve AWS credentials
aws_access_key_id = getEnvVar('AWS_ACCESS_KEY_ID')
aws_secret_access_key = getEnvVar('AWS_SECRET_ACCESS_KEY')
# Initialize a session using Boto3
session = boto3.Session(
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key
)
# Create an S3 client
s3_client = session.client('s3')
# List all buckets
try:
response = s3_client.list_buckets()
buckets_list = [bucket['Name'] for bucket in response['Buckets']]
print("Buckets List:", buckets_list)
except Exception as e:
print(f"Error listing buckets: {e}")
copied