From 1a1499a1895043bf6ce0b0e109f130cbe61b8dd3 Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Fri, 27 Jan 2023 16:10:27 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=87=E3=83=BC=E3=82=BF=E7=99=BB?= =?UTF-8?q?=E9=8C=B2=E5=87=A6=E7=90=86=20=E5=88=9D=E6=9C=9F=E5=87=A6?= =?UTF-8?q?=E7=90=86=E5=86=85=E3=81=AEresource=E3=82=A4=E3=83=B3=E3=82=BF?= =?UTF-8?q?=E3=83=95=E3=82=A7=E3=83=BC=E3=82=B9=E3=82=92=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=82=A2=E3=83=B3=E3=83=88=E3=82=A4=E3=83=B3=E3=82=BF?= =?UTF-8?q?=E3=83=95=E3=82=A7=E3=83=BC=E3=82=B9=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecs/dataimport/dataimport/ini.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/ecs/dataimport/dataimport/ini.py b/ecs/dataimport/dataimport/ini.py index 30d2ef93..098e2b2f 100644 --- a/ecs/dataimport/dataimport/ini.py +++ b/ecs/dataimport/dataimport/ini.py @@ -1,12 +1,12 @@ -from datetime import datetime -import boto3 -import io import csv +import io import re import sys -from error import error -from error import error_doing_file_exists +from datetime import datetime + +import boto3 from common import debug_log +from error import error, error_doing_file_exists # 定数 LOG_LEVEL = {"i": 'Info', "e": 'Error'} @@ -17,7 +17,6 @@ DIRECTORY_SETTINGS = '/settings/' # クラス変数 s3_client = boto3.client('s3') -s3_resource = boto3.resource('s3') def init(bucket_name, target_key, target_data_source, target_file_name, log_info, mode): @@ -60,8 +59,7 @@ def init(bucket_name, target_key, target_data_source, target_file_name, log_info try: # ③ S3バケット内のtargetディレクトリに、「投入データファイル名.doing」ファイルを作成する - doing_obj = s3_resource.Object(bucket_name, doing_key) - doing_obj.put(Body='') + s3_client.put_object(Bucket=bucket_name, Key=doing_key, Body=b'') print(f'{datetime.now():%Y-%m-%d %H:%M:%S} {log_info} {LOG_LEVEL["i"]} I-INI-04 - targetディレクトリに {doing_file_name} を作成しました') # ④ 投入データファイルをS3バケット内のtargetディレクトリから、workディレクトリに移動(コピー削除)する @@ -70,8 +68,7 @@ def init(bucket_name, target_key, target_data_source, target_file_name, log_info 'Key': target_key } work_key = target_data_source + DIRECTORY_WORK + target_file_name - work_obj = s3_resource.Object(bucket_name, work_key) - work_obj.copy(copy_source) + s3_client.copy(CopySource=copy_source, Bucket=bucket_name, Key=work_key) s3_client.delete_object(Bucket=bucket_name, Key=target_key) print(f'{datetime.now():%Y-%m-%d %H:%M:%S} {log_info} {LOG_LEVEL["i"]} I-INI-05 - 投入データ {target_file_name} をworkディレクトリに移動しました') except Exception as e: @@ -122,9 +119,8 @@ def init(bucket_name, target_key, target_data_source, target_file_name, log_info try: # ⑦ 個別設定ファイルを特定する print(f'{datetime.now():%Y-%m-%d %H:%M:%S} {log_info} {LOG_LEVEL["i"]} I-INI-17 - 個別設定ファイルを検索します') - mapping_obj = s3_resource.Object(bucket_name, mapping_key) - mapping_response = mapping_obj.get() - mapping_body = io.TextIOWrapper(io.BytesIO(mapping_response["Body"].read()), encoding='utf-8') + mapping_obj_response = s3_client.get_object(Bucket=bucket_name, Key=mapping_key) + mapping_body = io.TextIOWrapper(io.BytesIO(mapping_obj_response["Body"].read()), encoding='utf-8') settings_file_name = '' for row in csv.reader(mapping_body, delimiter='\t'): if row: