Replies: 4 comments 1 reply
-
I would like to have real data from people that have tried this runtime and struggled to understand its semantics. I have several real cases where the semantics of those other runtimes lead to many performance issues during cold start because people put shared initialization inside the handler functions. I do not want to have an interface that promotes bad practices.
This example is reimplementing our current interface, with worse semantics, and an extra layer of indirection. How are you passing shared resources here? With the current semantics it's much more explicit. By trying to hide a few basic Rust concepts, this is raising more questions than it really answers.
Can you expand on this? I don't understand what it means, which second pathway? why do we need more layers? |
Beta Was this translation helpful? Give feedback.
-
Hello guys, If I can add my 2 cents The current implementation of Rust is ok when you get used to the verbosity of the language, but as @timClicks, maybe it can be improved to make it cleaner. var authorizer *auth.Authorizer
func init() {
authorizer = .....
}
func main() {
lambda.Start(handleRequest)
}
func handleRequest(ctx context.Context, event events.APIGatewayCustomAuthorizerRequestTypeRequest) (events.APIGatewayCustomAuthorizerResponse, error) {
authorizer.doSomething()
} But I do not like the Tim syntax is nice: use lambda_runtime::{Event /* No need for Lambda prefix */, Error, handler};
use serde_json::{json, Value};
fn init() {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.init();
let config = aws_config::load_from_env().await;
let dynamodb_client = aws_sdk_dynamodb::Client::new(&config);
}
#[handler(init = init)]
async fn handler(event: Event<Value>) -> Result<Value, Error> {
Ok(json!({ }))
} Now the question would be how you pass all your initialisation, like |
Beta Was this translation helpful? Give feedback.
-
@timClicks I would argue that the current approach with We don't have the true and only async runtime in Rust on the language level, and people who are familiar with async Rust will be more comfortable with the current approach, which is more explicit. I personally would have more questions from seeing People learning async Rust are more likely see So I don't think deleting those 5 extra lines is worth it from the perspective of explicitness and clarity. P.S. As other people pointed out you also have |
Beta Was this translation helpful? Give feedback.
-
With Python, Typescript, etc. I can upload a small source file as my lambda function and have it running with almost the absolute minimal amount of ceremony possible. There would need to be a considerable amount of integration work to close the gap for learning projects and small scripts, probably including AWS console work. For example, if I just need a script to tune GameLift fleet settings every few minutes, Rust isn't a great tool for the job because of the added process to make a quick adjustment. Where Rust really shines is when you grow a thing and start running into issues where Python and likely Typescript become a worse fit for the Lambda platform. I'm going to speak to Python because I have more experience and currently use a split of Rust and Python for serverless functions.
The gap I'd like to see closed is around some of the functionality Lambda Power Tools provides, because that helps build the things we choose to build in Rust instead of Python, etc. due to fitness of the core technology. |
Beta Was this translation helpful? Give feedback.
-
I'm concerned that developers that might be put off by the Rust runtime because it makes a poor first impression.
Let's consider a minimal example of a Lambda handler in TypeScript:
And a minimal example in Python:
And now Rust:
With some thought, we could do much better than that. Here's a sketch:
Previous versions of the runtime actually included such a proc macro. It was removed in #282 for a few reasons.
I want to address the last point first: I do think that a helper macro does remove enough heavy lifting to justify its inclusion. As mentioned earlier, we can make the developer experience much better. Hopefully we can make it so good that using the Rust runtime feels like using a scripting language.
I'll need to dig into the concern about error reporting. This seems like a very important thing to get right. I wouldn't want to proceed with my idea if we end up making things harder for developers rather than easier.
There's the question about how to do any sort of global initialization/setup. This is a valid concern. Perhaps we could add an argument to the
handler
attribute?There's also a concerned about added confusion. Suddenly there is now an additional way to the runtime.
I would argue that
#[tokio::main]
also provides a second pathway totokio
. I would like the new#[handler]
attribute to be more of a short cut than a new route. It would be easy to peel back the layers.It may seem trivial to focus on how handlers are initialized, but there will be many people looking at Rust who have come from Python/TypeScript and who want more performance. But they're nervous. They have heard that Rust is difficult to learn and get right. They have less experience with Rust and less ability to correct themselves if they get into errors.
Beta Was this translation helpful? Give feedback.
All reactions