CSV파일 S3에 다이렉트 저장하기
Sample : Pandas DataFrame ( 24 X 5 )
from io import StringIO
import boto3
s3 = boto3.client('s3')
bucket = 'string' # Put Bucket Name
csv_buffer = StringIO()
df.to_csv(csv_buffer)
s3.put_object(Bucket=bucket, Body=csv_buffer.getvalue(), Key='df.csv')
S3에 저장되어 있는 CSV파일 다이렉트 읽기
import boto3
import pandas as pd
import io
s3 = boto3.client('s3')
bucket = 'string'
obj = s3.get_object(Bucket=bucket, Key="df.csv")
df = pd.read_csv(io.BytesIO(obj["Body"].read()))
CSV파일이나 정형화 되어 있는 Log 파일들을 S3로 바로 읽기/쓰기 바로바로 편집할 수 있다.
'AWS Infra' 카테고리의 다른 글
[ AWS ] Python boto3를 이용하여 ElastiCache Database 메모리 사용량 확인 (0) | 2023.05.31 |
---|---|
[ AWS ] Python boto3를 이용한 EC2 Instance 정보 구하기 (0) | 2023.05.22 |
[ AWS ] Python boto3를 이용하여 WAF IPset IP 수정하기 (0) | 2023.05.16 |
[ AWS ] Python boto3를 이용하여 RDS Connections 데이터 추출 하기 (0) | 2023.05.11 |
[ AWS ] Python boto3를 이용하여 ELB Metric 모니터링 (0) | 2023.05.10 |
[ AWS ] Python boto3를 이용하여 Target Group Health 모니터링 (0) | 2023.04.25 |
[ AWS ] Python boto3를 이용하여 S3 object 스토리지 클래스 변경 (0) | 2023.03.21 |
[ AWS ] Python boto3를 이용하여 s3 log 압축파일(gz) DataFrame 만들기 - CloudFront Logs (0) | 2023.03.16 |