python - 测试一个将 chalice 与 moto 一起使用的 lambda?

标签 python lambda boto3 chalice moto

我想使用 boto3、moto、pytest 在本地测试我的 lambda。这个 lambda 正在使用 chalice 。当我调用该函数时,我尝试插入一个假事件以使其运行,但它仍然缺少上下文对象。

如果有人知道如何以最干净的方式对其进行测试,那就太好了。

  • 我试图在我的 s3 中添加对象并从中检索事件
  • 我试图模拟假事件

  • @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/

    相关文章:

    Python Boto3 'StreamingBody' 对象没有属性 'iter_lines'

    Python 观察者设计模式

    c# - Python脚本可以在Windows应用商店应用程序中执行吗?

    c# - 表达式树依赖分析器

    python - 从 DynamoDB 获取项目时出现 "The provided key element does not match the schema"错误

    python - 无法使用 python 从 AWS dynamodb 获取项目?

    python - 当字符串传递给函数时,特殊字符编码会丢失

    jquery - 如何在 python 中编写自动建议搜索?

    java - 如何使用collect方法的第三个参数(combiner)?

    c++ - 如何从 lambda 中的函数返回?