일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- zip()
- permutations
- Split
- List 초기화
- string
- python3
- Boto3
- index
- Python 몫
- 프로그래머스
- cask
- List to String
- 알고리즘 풀이
- list.sorted()
- sort()
- Python 나머지
- Modified Date
- 알고리즘
- list.pop(0)
- 피보나치 수
- Python
- List
- set to list
- RecursionError
- list to set
- Unknown command: cask
- homebrew-core is a shallow clone.
- COUNT
- sting position
- Algorithm
- Today
- Total
데이터와 코드로 세상을 바라봅니다.
[AWS] S3 / Lambda / Python / File Name Check / Modified Date : 특정 일자, 파일 명칭 정상 여부 체크 로직 본문
[AWS] S3 / Lambda / Python / File Name Check / Modified Date : 특정 일자, 파일 명칭 정상 여부 체크 로직
코드우드 2021. 1. 5. 14:16import json
import boto3
from datetime import datetime, timedelta
src_bucket = '{버킷 명}'
file_upload_date = str(datetime(2020, 12, 14).strftime("%Y%m%d"))
def check_data_form_yyyymm(yyyymm) :
result = False
if len(yyyymm) == 6 and yyyymm.isdigit():
result = True
return result
def get_s3_file_name_list(file_upload_date) :
s3 = boto3.client('s3', region_name='ap-southeast-2')
response = s3.list_objects_v2(Bucket=src_bucket)
s3_file_name_list = []
for object in response['Contents'] :
if str(object['LastModified'].strftime("%Y%m%d")) == file_upload_date :
s3_file_name_list.append(object['Key'])
splited_file_name_list = []
for name_check_object in s3_file_name_list :
splited_s3_file_name = []
splited_s3_file_name = name_check_object.split("/")
splited_file_name_list.append(splited_s3_file_name[-1])
return splited_file_name_list
def check_fine_name_extension(file_name_list) :
result = True
for extension_check_object in file_name_list :
splited_file_name = []
splited_file_name = extension_check_object.split(".")
file_name_extension = splited_file_name[-1]
if (file_name_extension != "chk") and (file_name_extension != "csv") :
result = False
return result
def check_file_telegram(file_name_list) :
result_file_name = True
result_yyyymm = True
result = True
for telegram_check_object in file_name_list :
splited_file_name = []
splited_file_name = telegram_check_object.split(".")
file_name_telegram = splited_file_name[0]
splited_file_name_telegram = []
splited_file_name_telegram = file_name_telegram.split("_")
if len(splited_file_name_telegram) == 2 :
if (splited_file_name_telegram[0] == "A") :
result_file_name = True
elif (splited_file_name_telegram[0] == "B") :
result_file_name = True
else :
result_file_name = False
else :
result_file_name = False
## 날짜 YYYYMM 여부 확인
result_yyyymm = (result_yyyymm and check_data_form_yyyymm(splited_file_name_telegram[-1]))
## 작업 대상 목록 전체 점검 중 한개라도 False면 False 처리
if result_file_name == False :
result = False
elif result_yyyymm == False :
result = False
return result
def lambda_handler(event, context):
# TODO implement
print(check_fine_name_extension(get_s3_file_name_list(file_upload_date)))
print(check_file_telegram(get_s3_file_name_list(file_upload_date)))
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
[전역 변수]
src_bucket : 버킷 명
file_upload_date : 업로드 발생 일
[사용 함수]
get_s3_file_name_list(file_upload_date) : 특정 S3에 있는 파일 전체 중 업로드 발생 일에 해당하는 파일 리스트 일체
check_fine_name_extension(file_name_list) : 파일 확장자 검수
check_file_telegram(file_name_list) : 파일 명 검수
check_data_form_yyyymm(yyyymm) : YYYYMM 형식이 일치하는지 확인하는 함수
[Reference]
www.python2.net/questions-21830.htm
bash - 마지막 수정 날짜 조건을 가진 여러 s3 버킷 파일 삭제
최종 수정날짜 조건을 가진 여러 S3 파일을 어떻게 삭제합니까? s3에이 폴더 구조가 있습니다. dentca-lab-dev-sample 2019-03-13 file1 최종 수정 : 2019 년 3 월 13 일 2:34:06 GMT-0700 file2 최종 수정 : 2019 년 3 월 1
www.python2.net
stackoverrun.com/ko/q/12228439
www.tutorialspoint.com/datetime-compare-method-in-chash
DateTime.Compare() Method in C#
DateTime.Compare() Method in C# The DateTime.Compare() method in C# is used for comparison of two DateTime instances. It returns an integer value, <0 − If date1 is earlier than date20 − If date1 is the same as date2>0 − If date1 is later than date2 S
www.tutorialspoint.com
split이용한 배열의 마지막 값을 가져오는 방법
split이용한 배열의 마지막 값을 가져오는 방법 String filepath = "C:\\Users\\402-08\\Desktop\\jp\\Penguins.jpg"; // \\을 기준으로 데이터를 나누어 ar에 데이터를 넣어준다 . String[] ar = filepath.split..
tstigma.tistory.com
qastack.kr/programming/21388541/how-do-you-check-in-python-whether-a-string-contains-only-numbers
파이썬에서 문자열에 숫자 만 포함되어 있는지 어떻게 확인합니까?
qastack.kr
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#client
S3 — Boto3 Docs 1.16.47 documentation
A dictionary with two elements: url and fields. Url is the url to post to. Fields is a dictionary filled with the form fields and respective values to use when submitting the post. For example: {'url': 'https://mybucket.s3.amazonaws.com 'fields': {'acl': '
boto3.amazonaws.com
'Code > Python' 카테고리의 다른 글
[Python3] 2018 KAKAO BLIND RECRUITMENT - [1차] 비밀지도 (0) | 2021.01.08 |
---|---|
[Python3] - List, Remove (0) | 2021.01.07 |
[Python3] - 2019 KAKAO BLIND RECRUITMENT, 실패율, Max, Index, Len (0) | 2020.12.07 |
[Python3] - K번째수 (0) | 2020.11.30 |
[Python3] LRU(algorithm) - 2018 KAKAO BLIND RECRUITMENT[1차] 캐시 (0) | 2020.11.26 |