2

I want to test my lambda in local using boto3, moto, pytest. This lambda is using chalice. When I call the function I try to insert a fake event to make it run but it still missing the context object.

If someone know how to test it the cleanest way possible it'll be great.

  • I tried to add objects in my s3 and retrieve events from it
  • I tried to simulate fake events
@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)

Here is the lambda I want to test. Thanks for your responses.

Edwyn
  • 31
  • 2

1 Answers1

1

If someone get the same problem it's because chalice use a wrapper. Add your notification and a context in your handler.

Edwyn
  • 31
  • 2
  • 2
    Can you elaborate on how you test your event handler? I'm trying to write integration test for Chalice based event handlers but still struggling? Thanks – JSNoob May 05 '20 at 17:06