Skip to content

Instantly share code, notes, and snippets.

@allanbatista
Created December 18, 2019 17:22
Show Gist options
  • Save allanbatista/190d5561507976bdef08dffacfaa3279 to your computer and use it in GitHub Desktop.
Save allanbatista/190d5561507976bdef08dffacfaa3279 to your computer and use it in GitHub Desktop.
Use boto3 to access GCS as S3

Use boto3 to access GCS as S3

Enable Interoperability and generate a Access Key and Secret Key.

install requirements

pip3 install boto3

running

export ACCESS_KEY=xx
export SECRET_KEY=yy
export BUCKET=xxx
python3 example.py
import os
from boto3.session import Session
from botocore.client import Config
ACCESS_KEY = os.environ['ACCESS_KEY']
SECRET_KEY = os.environ['SECRET_KEY']
session = Session(aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
s3 = session.resource('s3', endpoint_url='https://storage.googleapis.com', config=Config(signature_version='s3v4'))
bucket = s3.Bucket(os.environ['BUCKET'])
for f in bucket.objects.all():
print(f.key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment