Menjaga objek tetap aman

Pengantar AWS Boto di Python

Maksim Pecherskiy

Data engineer

Mengapa peduli izin?

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

Ikhtisar izin

Pengantar AWS Boto di Python

Mengapa peduli izin?

Izin diizinkan!

# 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')
Pengantar AWS Boto di Python

Sistem izin AWS

IAM

Kebijakan Bucket

ACL

URL prasinandai

Pengantar AWS Boto di Python

Sistem izin AWS

IAM

Kebijakan Bucket

ACL

URL prasinandai

Pengantar AWS Boto di Python

ACL

ACL

Pengantar AWS Boto di Python

ACL

Unggah file

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

Setel ACL ke 'public-read'

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

Menyetel ACL saat unggah

Unggah file dengan ACL 'public-read'

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

Mengakses objek publik

Templat URL objek S3

https://{bucket}.{key}

URL untuk Key='2019/potholes.csv'

https://gid-requests.2019/potholes.csv
Pengantar AWS Boto di Python

Membuat URL objek publik

Hasilkan string URL objek

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

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

# Baca URL ke Pandas
df = pd.read_csv(url)
Pengantar AWS Boto di Python

Cara akses diputuskan

Hierarki akses

Pengantar AWS Boto di Python

Cara akses diputuskan

Hierarki akses

Pengantar AWS Boto di Python

Ringkasan

IAM

Kebijakan Bucket

ACL

URL prasinandai

Pengantar AWS Boto di Python

Ringkasan

Setel ACL ke 'public-read'

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

Setel ACL ke 'private'

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

Ringkasan

Unggah file dengan ACL 'public-read'

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

Ringkasan

Hasilkan string URL objek

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

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

# Baca URL ke Pandas
df = pd.read_csv(url)
Pengantar AWS Boto di Python

Ayo berlatih!

Pengantar AWS Boto di Python

Preparing Video For Download...