Sécuriser les objets

Introduction à AWS Boto en Python

Maksim Pecherskiy

Data engineer

Pourquoi les autorisations comptent-elles ?

df = pd.read_csv('https://gid-staging.potholes.csv')

Aperçu des autorisations

Introduction à AWS Boto en Python

Pourquoi les autorisations comptent-elles ?

Autorisation accordée !

# Generate the boto3 client for interacting with S3
s3 = boto3.client('s3', region_name='us-east-1', 
                         aws_access_key_id=AWS_KEY_ID, 
                         aws_secret_access_key=AWS_SECRET)

# Use client to download a file s3.download_file( Filename='potholes.csv', Bucket='gid-requests', Key='potholes.csv')
Introduction à AWS Boto en Python

Systèmes d'autorisations AWS

IAM

Stratégie de compartiment

ACL

URL présignée

Introduction à AWS Boto en Python

Systèmes d'autorisations AWS

IAM

Stratégie de compartiment

ACL

URL présignée

Introduction à AWS Boto en Python

ACL

ACL

Introduction à AWS Boto en Python

ACL

Téléverser un fichier

s3.upload_file(
  Filename='potholes.csv', Bucket='gid-requests', Key='potholes.csv')

Définir l'ACL sur 'public-read'

s3.put_object_acl(
  Bucket='gid-requests', Key='potholes.csv', ACL='public-read')
Introduction à AWS Boto en Python

Définir l'ACL au téléversement

Téléverser avec l'ACL 'public-read'

s3.upload_file(
  Bucket='gid-requests', 
  Filename='potholes.csv', 
  Key='potholes.csv', 
  ExtraArgs={'ACL':'public-read'})
Introduction à AWS Boto en Python

Accéder aux objets publics

Modèle d'URL d'objet S3

https://{bucket}.{key}

URL pour Key='2019/potholes.csv'

https://gid-requests.2019/potholes.csv
Introduction à AWS Boto en Python

Générer l'URL d'un objet public

Générer la chaîne d'URL d'objet

url = "https://{}.{}".format(
  "gid-requests", 
  "2019/potholes.csv")

'https://gid-requests.2019/potholes.csv'

# Read the URL into Pandas
df = pd.read_csv(url)
Introduction à AWS Boto en Python

Comment l'accès est décidé

Hiérarchie d'accès

Introduction à AWS Boto en Python

Comment l'accès est décidé

Hiérarchie d'accès

Introduction à AWS Boto en Python

Révision

IAM

Stratégie de compartiment

ACL

URL présignée

Introduction à AWS Boto en Python

Révision

Définir l'ACL sur 'public-read'

s3.put_object_acl(
  Bucket='gid-requests', Key='potholes.csv', ACL='public-read')

Définir l'ACL sur 'private'

s3.put_object_acl(
  Bucket='gid-requests', Key='potholes.csv', ACL='private')
Introduction à AWS Boto en Python

Révision

Téléverser avec l'ACL 'public-read'

s3.upload_file(
  Bucket='gid-requests', 
  Filename='potholes.csv', 
  Key='potholes2.csv', 
  ExtraArgs={'ACL':'public-read'})
Introduction à AWS Boto en Python

Révision

Générer la chaîne d'URL d'objet

url = "https://{}.{}".format(
  "gid-requests", 
  "2019/potholes.csv")

'https://gid-requests.2019/potholes.csv'

# Read the URL into Pandas
df = pd.read_csv(url)
Introduction à AWS Boto en Python

Passons à la pratique !

Introduction à AWS Boto en Python

Preparing Video For Download...