-
Notifications
You must be signed in to change notification settings - Fork 347
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
how to initialize SDK client outside of function handler #616
Comments
the following example does something similar, can you model your approach off of this? |
Thank you for your answer, but I could not do it. #[tokio::main]
async fn main() -> Result<(), Error> {
let s3_client = get_client().await;
let client = move || &SharedClient::new(&s3_client);
let client_ref = client();
run(service_fn(
move |_event: LambdaEvent<S3Event>| async move {
Ok::<Response, Error>(client_ref.put_file_x().await)
}
))
.await?;
Ok(())
} It does not compile:
Unfortunately I am far from the level to solve this or to decide where to go. |
Another rust beginner here, same question. Would be helpful to add a more complete example. Edit: |
I just submitted a PR for a basic SDK example. probably worth having one of those in the repo to show sharing of the client along with an example of how to test code that interacts with the SDK. does this help clarify the recommended approach? |
Thank you, it works. I clean up my code a bit and send a PR. |
|
For reference: |
Dear Developers,
I created an example for s3:
peterborkuti@dbc5d3d
It works, but as I read aws best practices for lambda:
https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html
"Initialize SDK clients and database connections outside of the function handler"
I could not do it (I am absolute beginner in Rust but I have solid knowledge in Java and JavaScript)
What I tried
creating static/const but client creation is async
const client: Client = get_client().await;
static mut
using lambdas context in main
(With the above handler testing would be very easy, I think, because the client is "embedded" in the fn_get_file and fn_put_file functions, so when testing we do not need sdk client at all)
in main I tried to binding the client parameters to fn_get_file and fn_put_file:
First I had lifetime issues (tried to solve with "move" and now I got:"expected a closure that implements the
Fn
trait, but this closure only implementsFnOnce
":Do you have any ideas how to do it?
Thank you in advance
Péter
The text was updated successfully, but these errors were encountered: