Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rust support for AWS Lambda Powertools #37

Open
michaelbrewer opened this issue Nov 11, 2021 · 10 comments
Open

Add Rust support for AWS Lambda Powertools #37

michaelbrewer opened this issue Nov 11, 2021 · 10 comments
Labels
Pending/Triage Pending triage Proposed Community submited

Comments

@michaelbrewer
Copy link
Contributor

Runtime:
Rust

Is your feature request related to a problem? Please describe
In the Serverless Lens for the Well Architected Framework, we suggest several best practices for observability such as structured logging, distributed tracing, and monitoring of metrics. The suite of utilities of the AWS Lambda Powertools help developers with the adoption of best practices.
Today, AWS Lambda Powertools is available for the Python and Java runtimes.

In addition to the powertools the crate, the documentation site can help people new to Rust and AWS Lambda to get up in running

Describe the solution you'd like
AWS Lambda Powertools available for Provided runtimes, written in Rust.

Describe alternatives you've considered
There is almost no alternatives or guidance that i have seen so far.

If you provide guidance, is this something you'd like to contribute?
Absolutely yes.

Additional context
The Rust Powertools will follow the same tenets as the other languages, and folks can expect the same core utilities/ functionalities being supported.

This request is based on #26 :)

@michaelbrewer michaelbrewer added Pending/Triage Pending triage Proposed Community submited labels Nov 11, 2021
@michaelbrewer
Copy link
Contributor Author

I assume @nmoutschen you are already running this and have a crate (namespace)

@nmoutschen
Copy link

I assume @nmoutschen you are already running this and have a crate (namespace)

Yep! I've reserved the lambda-powertools crate and am working on a DX proposal at the moment.

@ZackKanter
Copy link

Any chance of re-opening this ticket?

@heitorlessa
Copy link
Contributor

@ZackKanter thanks for the nudge!

As of now, we don't have plans to create Lambda Powertools for Rust due to skill set (@nmoutschen left) and staffing (not planned in the foreseeable future for Rust) -- We'll happily update this issue if that changes it.

@heitorlessa heitorlessa reopened this Sep 19, 2022
@nabsource
Copy link

Not sure if anything has changed, but wanted to say this would be welcome

@BMorinDrifter
Copy link

I'm doing some work to close the gap a bit, at least for metrics.

https://crates.io/crates/metrics_cloudwatch_embedded

Example

use lambda_runtime::{Error, LambdaEvent};
use metrics_cloudwatch_embedded::lambda::handler::run;
use serde::{Deserialize, Serialize};

#[derive(Deserialize)]
struct Request {}

#[derive(Serialize)]
struct Response {
}

async fn function_handler(event: LambdaEvent<Request>) -> Result<Response, Error> {
    metrics::increment_counter!("requests", "Method" => "Default");

    Ok(Response {})
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt()
        .with_env_filter(tracing_subscriber::filter::EnvFilter::from_default_env())
        .with_target(false)
        .without_time()
        .compact()
        .init();

    let metrics = metrics_cloudwatch_embedded::Builder::new()
        .cloudwatch_namespace("MetricsExample")
        .with_dimension("Function", std::env::var("AWS_LAMBDA_FUNCTION_NAME").unwrap())
        .lambda_cold_start_metric("ColdStart")
        .with_lambda_request_id("RequestId")
        .init()
        .unwrap();

    run(metrics, function_handler).await
}

Output

START RequestId: 4bd2d365-3792-46c8-9b6c-6132f9630fbb Version: $LATEST
{"_aws":{"Timestamp":1687947426188,"CloudWatchMetrics":[{"Namespace":"MetricsTest","Dimensions":[["Function"]],"Metrics":[{"Name":"ColdStart","Unit":"Count"}]}]},"Function":"MetricsTest","RequestId":"4bd2d365-3792-46c8-9b6c-6132f9630fbb","ColdStart":1}
{"_aws":{"Timestamp":1687947426188,"CloudWatchMetrics":[{"Namespace":"MetricsTest","Dimensions":[["Function","Method"]],"Metrics":[{"Name":"requests"}]}]},"Function":"MetricsTest","Method":"Default","RequestId":"4bd2d365-3792-46c8-9b6c-6132f9630fbb","requests":1}
END RequestId: 4bd2d365-3792-46c8-9b6c-6132f9630fbb
REPORT RequestId: 4bd2d365-3792-46c8-9b6c-6132f9630fbb Duration: 1.28 ms Billed Duration: 22 ms Memory Size: 128 MB Max Memory Used: 14 MB Init Duration: 20.02 ms

Under the hood tower::Service is used to hook up decoration before the handler (or inner service) and to flush metrics after the handler.

@philschmid
Copy link

Is there an update on this? @nmoutschen

@nmoutschen
Copy link

Is there an update on this? @nmoutschen

I no longer work at AWS, so unfortunately, I do not know

@heitorlessa
Copy link
Contributor

heitorlessa commented Dec 11, 2023 via email

@philschmid
Copy link

Too bad i was hoping after the rust sdk v1 release this might come too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pending/Triage Pending triage Proposed Community submited
Projects
None yet
Development

No branches or pull requests

7 participants