Я использую лямбда-функцию, корзину s3 в моем коде Python.
Мне нужно написать модульное тестирование для моего лямбда-кода, может кто-нибудь помочь мне в том, как написать фиктивную функцию для службы s3
def lambda_handler(event, context):
# Locate the s3 bucket and the file once triggered
file_obj = event["Records"][0]
bucket_name = str(file_obj['s3']['bucket']['name'])
file_name = str(file_obj['s3']['object']['key'])
copy_source = {
'Bucket': bucket_name,
'Key': file_name
}
dest_bucket = 'sample.456'
# reading the file from the Landing bucket
data = s3.get_object(Bucket='sample.123', Key=file_name)
contents = data['Body'].read().decode('utf-8')
# adding and updating few characters to load the json file into lambda functiosnin
sample = '[' + str(contents).replace("\n", "") + ']'
str_search = "}"
str_replace = "},"
count = 0
fc = sample.count(str_search)
# looping the log file to convert timestamp to
if fc == 1:
# load as json file
jsonlst = {
"data": json.loads(sample)
}
time_conversion(jsonlst, file_name, dest_bucket)
else:
for t in range(0, fc - 1):
sample1 = sample.replace(str_search, str_replace)
sample2 = sample1.replace(',]', ']')
# load as json file
jsonlst = {
"data": json.loads(sample2)
}
time_conversion(jsonlst, file_name, dest_bucket)