70 %
Chris Biscardi

Running MeiliSearch in a Lambda

A couple findings:

  • You can cross-compile meilisearch/meilisearch for the netlify lambda environment using cargo build --target x86_64-unknown-linux-musl
  • You can execute one actix web route using the test infrastructure
  • You can drop a full my-data.ms/ into the right location and Meilisearch will pick it up and use it.

in meilisearch-http there is a binary at src/main.rs. If we clone that into src/lambda.rs and make a couple changes, we can fake a single request to the actix app.

src/main.rs
diff
let http_server = HttpServer::new(move || {
- let cors = Cors::default()
- .send_wildcard()
- .allowed_headers(vec!["content-type", "x-meili-api-key"])
- .allow_any_origin()
- .allow_any_method()
- .max_age(86_400); // 24h
- create_app(&data, enable_frontend)
- .wrap(cors)
- .wrap(middleware::Logger::default())
- .wrap(middleware::Compress::default())
- .wrap(NormalizePath)
- });
+ let app = create_app(&data, enable_frontend)
- .wrap(cors)
+ .wrap(middleware::Logger::default())
+ .wrap(middleware::Compress::default())
+ .wrap(NormalizePath);
+ let mut app = test::init_service(app).await;
+ let req = test::TestRequest::get().to_request();
+ let mut resp = test::call_service(&mut app, req).await;
+ dbg!(resp);
- if let Some(config) = opt.get_ssl_config()? {
- http_server
- .bind_rustls(opt.http_addr, config)?
- .run()
- .await?;
- } else {
- http_server.bind(opt.http_addr)?.run().await?;
- }