Skip to main content

Crate autumn_plugin_aws_athena

Crate autumn_plugin_aws_athena 

Source
Expand description

Autumn plugin for Amazon Athena.

Add AthenaPlugin to the app. Then use the Athena extractor in a handler.

use autumn_plugin_aws_athena::{Athena, AthenaPlugin, AthenaResultExt as _};
use autumn_web::prelude::*;

#[derive(serde::Deserialize, serde::Serialize)]
struct Order {
    id: i64,
    total: f64,
}

#[get("/customers/{id}/orders")]
async fn orders(athena: Athena, Path(id): Path<String>) -> AutumnResult<Json<Vec<Order>>> {
    let rows = athena
        .query("SELECT id, total FROM orders WHERE customer_id = ?")
        .bind(id)
        .fetch_as::<Order>()
        .await
        .or_http()?;
    Ok(Json(rows))
}

autumn_web::app()
    .plugin(AthenaPlugin::new())
    .routes(routes![orders])
    .run()
    .await;

The plugin reads [athena] in autumn.toml. See config for the keys.

§Security rules

  • Bind each value with AthenaQuery::bind. Do not put values into the SQL text.
  • Each query has a timeout, a row limit and a byte limit. The plugin stops a timed-out query in Athena.
  • Set BytesScannedCutoffPerQuery on the workgroup. This limits the cost of one query.
  • Logs have query IDs. Logs do not have SQL text or parameter values.

Re-exports§

pub use api::ApiError;
pub use api::AthenaApi;
pub use api::Column;
pub use api::FailureInfo;
pub use api::QueryState;
pub use api::StatementType;
pub use api::Statistics;
pub use config::AthenaConfig;
pub use config::PollConfig;
pub use literal::Param;
pub use sdk::SdkAthena;
pub use value::Row;
pub use value::Value;

Modules§

api
The seam between the plugin and Athena.
config
The [athena] section of autumn.toml.
literal
Athena SQL literals for execution parameters.
sdk
AthenaApi on the AWS SDK client.
testing
A scripted fake of Athena for tests.
value
Typed values and rows.

Structs§

Athena
A handle to Athena. Clones share one connection and one set of open queries.
AthenaPlugin
Installs an Athena handle in an Autumn app.
AthenaQuery
A query to run. Make one with Athena::query.
Execution
A query that succeeded.
QueryOutput
The rows of a query that succeeded.

Enums§

AthenaError
An error from the plugin.

Constants§

PLUGIN_NAME
The plugin name in Autumn diagnostics.

Traits§

AthenaResultExt
Adds or_http to Result<T, AthenaError>.