AWS Glue에서 Amazon S3 Express One Zone 사용
AWS Glue 버전 5.1 이상에서는 ETL 작업에서 Amazon S3 Express One Zone 디렉터리 버킷의 데이터를 읽고 쓸 수 있습니다. S3 Express One Zone은 지연 시간에 민감한 애플리케이션에서 일관되게 10밀리초 미만의 데이터 액세스를 지원하는 고성능 단일 영역 Amazon S3 스토리지 클래스입니다.
사전 조건
AWS Glue에서 S3 Express One Zone을 사용하려면 다음이 필요합니다.
-
버전 5.1 이상을 실행하는 AWS Glue 작업.
-
AWS Glue 작업과 동일한 리전에서 생성된 S3 디렉터리 버킷. 디렉터리 버킷은 교차 리전 액세스를 지원하지 않습니다. 자세한 내용은 Amazon S3 사용 설명서의 디렉터리 버킷 생성을 참조하세요.
-
IAM 역할에 대한
s3express:CreateSession권한. S3 Express One Zone이 디렉터리 버킷에 대한 작업을 수행할 때 사용자를 대신하여CreateSession을 직접적으로 호출합니다.
IAM 권한
S3 Express One Zone 디렉터리 버킷에 액세스할 수 있도록 AWS Glue 작업의 IAM 역할에 다음 권한을 추가합니다.
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "s3express:CreateSession", "Resource": "arn:aws:s3express:*:*:bucket/EXAMPLE-BUCKET--az-id--x-s3" } ] }
EXAMPLE-BUCKET을 디렉터리 버킷 이름으로 바꾸고 az-id를 가용 영역 ID(예: use1-az4)로 바꿉니다.
데이터 읽기 및 쓰기
AWS Glue 버전 5.1 이상은 s3:// 및 s3a:// URI 체계를 모두 사용하여 S3 Express One Zone 디렉터리 버킷에 대한 액세스를 지원합니다. 추가 구성은 필요하지 않습니다.
다음 예제에서는 AWS Glue ETL 작업에서 S3 Express One Zone 디렉터리 버킷의 데이터를 읽고 쓰는 방법을 보여줍니다.
import sys from pyspark.context import SparkContext from awsglue.context import GlueContext sc = SparkContext.getOrCreate() glueContext = GlueContext(sc) spark = glueContext.spark_session # S3 Express One Zone directory bucket path express_path = "s3://EXAMPLE-BUCKET--use1-az4--x-s3/my-data/" # Read data from S3 Express One Zone df = spark.read.parquet(express_path) # Write data to S3 Express One Zone df.write.mode("overwrite").parquet(express_path + "output/")
또한 S3 Express One Zone에서 DynamicFrames를 사용할 수 있습니다.
# Read with DynamicFrame dynamicFrame = glueContext.create_dynamic_frame.from_options( connection_type="s3", connection_options={"paths": [express_path]}, format="parquet" ) # Write with DynamicFrame glueContext.write_dynamic_frame.from_options( frame=dynamicFrame, connection_type="s3", connection_options={"path": express_path + "output/"}, format="parquet" )