데이터 조회 (방법 1)
config = LoadConfig("./config.yaml")
prefix = f"{config['bucketFirstDir']}/11/"
location = "ap-northeast-2"
s3 = boto3.client('s3', aws_access_key_id=config['awsAccessKey'], aws_secret_access_key=config['awsSecretKey'], region_name=location)
objList = s3.list_objects(Bucket=config['bucketName'], Prefix=prefix)
contentsList = objList['Contents']
fileList = []
for content in contentsList:
key = content['Key']
idx = key.rfind('/')
if key[:idx+1] == prefix and key != prefix:
fileList.append(key)
for file in fileList:
print(file)
데이터 조회(방법 2)
def RetrieveFile(container_id: str = '11'):
config = LoadConfig("./config.yaml")
s3Resource = boto3.resource(
's3',
aws_access_key_id=config["awsAccessKey"],
aws_secret_access_key=config["awsSecretKey"],
region_name=location,
)
prefix = f"{config['bucketFirstDir']}/{container_id}/"
bucket = s3Resource.Bucket(name=config['bucketName'])
for obj in bucket.objects.filter(Prefix=prefix):
print(f"{bucket.name}, {obj.key}")
else:
return ReturnMsg(False, "Not a valid objects", -2, None)