프라이빗 s3 버킷에 연결하고 파이썬으로 csv를 다운로드하고 싶습니다. 어떻게하나요? boto3에 대해 이야기하는 많은 댓글을 보았습니다. 그래서 이것이 제가 시도한 것이며 실패했습니다.
from boto3.session import Session
import pandas as pd
import boto3
ACCESS_KEY='A'
SECRET_KEY='s/'
session = Session(aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
s3 = session.resource('s3')
obj = s3.get_object(Bucket='sp-dps', Key='da-la/hp/hp_co/current')
df = pd.read_csv(obj['Body'])
import boto
from boto.s3.key import Key
keyId ="xxx" (AWS KEY)
sKeyId="yyy" (AWS SECRET KEY ID)
srcFileName="/abc/def/ghi/jkl/part_data_1"
destFileName="s3_part_data_1.csv"
bucketName="s-bucket"
conn = boto.connect_s3(keyId,sKeyId)
bucket = conn.get_bucket(bucketName)
#Get the Key object of the given key, in the bucket
k = Key(bucket,srcFileName)
#Get the contents of the key into a file
k.get_contents_to_filename(destFileName)
위의 코드는 올바른 코드입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다