我想使用 boto3、moto、pytest 在本地测试我的 lambda。这个 lambda 正在使用 chalice 。当我调用该函数时,我尝试插入一个假事件以使其运行,但它仍然缺少上下文对象。
如果有人知道如何以最干净的方式对其进行测试,那就太好了。
@app.on_s3_event(bucket=s.BUCKET_NAME, events=['s3:ObjectCreated:*'], prefix=s.PREFIX_PREPROCESSED, suffix=s.SUFFIX)
def handle_pre_processed_event(event):
"""
Lambda for preprocessed data
:param event:
:return:
"""
# Retrieve the json that was add to the bucket S3
json_s3 = get_json_file_s3(event.bucket, event.key)
# Send all the records to dynamoDB
insert_records(json_s3)
# Change the path of the file by copying it and delete it
change_path_file(event.key, s.PREFIX_PREPROCESSED)
这是我要测试的 lambda。感谢您的回复。
最佳答案
如果有人遇到同样的问题,那是因为 chalice 使用了包装器。在您的处理程序中添加您的通知和上下文。
关于python - 测试一个将 chalice 与 moto 一起使用的 lambda?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55854098/