AWS可以通过使用AWS Glue和Amazon EMR等工具对大量数据进行随机化。下面是使用AWS Glue进行数据随机化的例子:
import boto3
import random
s3_client = boto3.client('s3')
bucket_name = 'my-bucket'
prefix = 'raw-data/'
# get a list of objects in the s3 bucket
bucket_objects = s3_client.list_objects(Bucket=bucket_name, Prefix=prefix)['Contents']
# shuffle the list of objects
random.shuffle(bucket_objects)
# copy the objects back to the same location in s3 with new keys
for i, obj in enumerate(bucket_objects):
s3_client.copy_object(
Bucket=bucket_name,
CopySource={'Bucket': bucket_name, 'Key': obj['Key']},
Key=f"raw-data/{i + 1}.csv"
)
这个例子将具有相同前缀“raw-data/”的S3桶中的CSV文件随机复制到同一位置,并用新的键作为新的文件名。可以通过在代码中进行更改以满足您的数据需求。
上一篇:AWS如何处理退信和投诉?