Objekte sicher halten

Einführung in AWS Boto mit Python

Maksim Pecherskiy

Data engineer

Warum sind Berechtigungen wichtig?

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

Berechtigungsübersicht

Einführung in AWS Boto mit Python

Warum sind Berechtigungen wichtig?

Berechtigung erlaubt!

# 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')
Einführung in AWS Boto mit Python

AWS-Berechtigungssysteme

IAM

Bucket-Richtlinie

ACL

Vorsignierte URL

Einführung in AWS Boto mit Python

AWS-Berechtigungssysteme

IAM

Bucket-Richtlinie

ACL

Vorsignierte URL

Einführung in AWS Boto mit Python

ACLs

ACL

Einführung in AWS Boto mit Python

ACLs

Datei hochladen

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

ACL auf 'public-read' setzen

s3.put_object_acl(
  Bucket='gid-requests', Key='potholes.csv', ACL='public-read')
Einführung in AWS Boto mit Python

ACLs beim Upload setzen

Datei mit 'public-read'-ACL hochladen

s3.upload_file(
  Bucket='gid-requests', 
  Filename='potholes.csv', 
  Key='potholes.csv', 
  ExtraArgs={'ACL':'public-read'})
Einführung in AWS Boto mit Python

Öffentliche Objekte aufrufen

S3-Objekt-URL-Vorlage

https://{bucket}.{key}

URL für Key='2019/potholes.csv'

https://gid-requests.2019/potholes.csv
Einführung in AWS Boto mit Python

Öffentliche Objekt-URL erzeugen

Objekt-URL-String erzeugen

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

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

# Read the URL into Pandas
df = pd.read_csv(url)
Einführung in AWS Boto mit Python

Wie über Zugriff entschieden wird

Zugriffshierarchie

Einführung in AWS Boto mit Python

Wie über Zugriff entschieden wird

Zugriffshierarchie

Einführung in AWS Boto mit Python

Zusammenfassung

IAM

Bucket-Richtlinie

ACL

Vorsignierte URL

Einführung in AWS Boto mit Python

Zusammenfassung

ACL auf 'public-read' setzen

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

ACL auf 'private' setzen

s3.put_object_acl(
  Bucket='gid-requests', Key='potholes.csv', ACL='private')
Einführung in AWS Boto mit Python

Zusammenfassung

Datei mit 'public-read'-ACL hochladen

s3.upload_file(
  Bucket='gid-requests', 
  Filename='potholes.csv', 
  Key='potholes2.csv', 
  ExtraArgs={'ACL':'public-read'})
Einführung in AWS Boto mit Python

Zusammenfassung

Objekt-URL-String erzeugen

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

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

# Read the URL into Pandas
df = pd.read_csv(url)
Einführung in AWS Boto mit Python

Lass uns üben!

Einführung in AWS Boto mit Python

Preparing Video For Download...