Is it possible to get a shared client as handler parameter to reduce the duration of the lambda? #581
-
Hi, I would like to implement this example. In order to reduce the time the lambda takes, I would like to just create the DynamoDB client once in the main function and re-use it in the handler, instead of creating the DynamoDB client on every invocation: async fn function_handler(event: Request, ssm_client: &aws_sdk_ssm::Client) -> Result<Response<Body>, Error> {} or how axum is doing it: async fn handler(State(client): State<Arc<Client>>) {} I had a look at the existing examples to share state, but in these the handler function got inlined in the main function. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
See this example that uses the S3 client defined in the main function: https://github.com/calavera/aws-rust-developer-guide-v1/blob/01744e7b319df226f88788171ed884c670b2e2ec/doc_source/lambda.md I've also updated the DynamoDB example to share the client, it's a better practice: #582 |
Beta Was this translation helpful? Give feedback.
See this example that uses the S3 client defined in the main function: https://github.com/calavera/aws-rust-developer-guide-v1/blob/01744e7b319df226f88788171ed884c670b2e2ec/doc_source/lambda.md
I've also updated the DynamoDB example to share the client, it's a better practice: #582