import boto3
def list_gcs_objects(google_access_key_id, google_access_key_secret, bucket_name):
"""Lists GCS objects using boto3 SDK"""
# Create a new client and do the following:
# 1. Change the endpoint URL to use the
# Google Cloud Storage XML API endpoint.
# 2. Use Cloud Storage HMAC Credentials.
client = boto3.client(
"s3",
region_name="auto",
endpoint_url="https://storage.googleapis.com",
aws_access_key_id=google_access_key_id,
aws_secret_access_key=google_access_key_secret,
)
# Call GCS to list objects in bucket_name
response = client.list_objects(Bucket=bucket_name)
# Print object names
print("Objects:")
for blob in response["Contents"]:
print(blob["Key"])