Beispiel #1
0
 def populate_appointments_table(cls, fast_mode=True):
     """
     Args:
         fast_mode: if True, uses ddb batch_writer to quickly populate the appointments table but items
             will not contain created, modified and type fields added by Dynamodb.put_item
     """
     if fast_mode:
         ddb_client = Dynamodb(stack_name=STACK_NAME)
         app_table = ddb_client.get_table(table_name=app.APPOINTMENTS_TABLE)
         with app_table.batch_writer() as batch:
             for appointment in test_data.appointments.values():
                 appointment["id"] = appointment["appointment_id"]
                 batch.put_item(appointment)
     else:
         for appointment_dict in test_data.appointments.values():
             appointment = app.AcuityAppointment(
                 appointment_dict["appointment_id"])
             appointment.from_dict(appointment_dict)
             at = app.AppointmentType()
             at.from_dict(appointment.appointment_type)
             appointment.appointment_type = at
             try:
                 appointment.ddb_dump()
             except utils.DetailedValueError:
                 cls.logger.debug(
                     "PutItem failed, which probably "
                     "means Appointment table already contains "
                     "the required test data; aborting this method",
                     extra={},
                 )
                 break
Beispiel #2
0
def persist_thiscovery_event(event, context):
    event.pop("logger", None)
    event.pop("correlation_id", None)
    ddb_client = Dynamodb(stack_name=const.STACK_NAME, correlation_id=event["id"])
    table = ddb_client.get_table(table_name=const.AUDIT_TABLE)
    result = table.put_item(Item=event)
    assert result["ResponseMetadata"]["HTTPStatusCode"] == HTTPStatus.OK
    return {"statusCode": HTTPStatus.OK, "body": json.dumps("")}