반응형
import boto3, botocore, configparser
def main(s3Client):
print('\nStart of create object script\n')
print('Reading configuration file for bucket name...')
config = readConfig()
bucket_name = config['bucket_name']
source_file_name = config["object_name"] + config['source_file_extension']
key_name = config['key_name']+ config['source_file_extension']
contentType = config['source_content_type']
metaData_key = config['metaData_key']
metaData_value = config['metaData_value']
print('Creating Object...')
print(uploadObject(s3Client, bucket_name, source_file_name, key_name, contentType, {metaData_key: metaData_value}))
print('\nEnd of create object script\n')
def uploadObject(s3Client, bucket, name, key, contentType, metadata={}):
response = s3Client.upload_file(
Bucket=bucket,
Key=key,
Filename=name,
ExtraArgs={
'ContentType': contentType,
'Metadata': metadata
}
)
return "Finished creating object\n"
def readConfig():
config = configparser.ConfigParser()
config.read('./labRepo/config.ini')
return config['S3']
client = boto3.client('s3')
try:
main(client)
except botocore.exceptions.ClientError as err:
print(err.response['Error']['Message'])
except botocore.exceptions.ParamValidationError as error:
print(error)
반응형
'Basic > Python' 카테고리의 다른 글
python collection 모듈 사용 방법 (0) | 2023.12.19 |
---|---|
python itertools 사용 방법 (0) | 2023.12.19 |
Python을 이용하여 S3 bucket 만드는 코드 (0) | 2023.10.11 |
[Python] 파이썬에서 filter나 map으로 나온 값 print 하는 방법 (0) | 2023.03.06 |
DALLE2 를 이용하여 저작권 없는 이미지 생성하기 (0) | 2023.02.20 |