Closed
Description
Pull Request #284 Introduced the Sync
requirement for all http lambdas.
This broke any http lambdas using any of these libraries:
- Rusoto
- Mongodb
- Sqlx
Reproduction
use lambda_http::{
handler,
lambda::{self, Context},
IntoResponse, Request, RequestExt, Response,
};
use serde_json::{json, Value};
use rusoto_core::Region;
use rusoto_dynamodb::{DynamoDb, DynamoDbClient, ListTablesInput};
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
#[tokio::main]
async fn main() -> Result<(), Error> {
lambda::run(handler(func)).await?;
Ok(())
}
async fn func(_: Request, _: Context) -> Result<Value, Error> {
let client = DynamoDbClient::new(Region::UsEast1);
let output = client.list_tables(Default::default()).await?;
dbg!{output};
Ok(json!({"success": true}))
}
[dependencies]
serde_json = "1.0"
serde = "1.0"
tokio = {version = "1.0", features = ["macros"]}
lambda_http = { git = "https://github.com/awslabs/aws-lambda-rust-runtime/", branch = "master"}
lambda = { git = "https://github.com/awslabs/aws-lambda-rust-runtime/", branch = "master"}
rusoto_dynamodb = "0.46.0"
rusoto_core = "0.46.0"
This is the error I get:
error: future cannot be shared between threads safely
--> src/main.rs:16:17
|
16 | lambda::run(handler(func)).await?;
| ^^^^^^^ future returned by `func` is not `Sync`
|
::: ~/.cargo/git/checkouts/aws-lambda-rust-runtime-7c865cce90132439/9bd45c1/lambda-http/src/lib.rs:109:19
|
109 | pub fn handler<H: Handler>(handler: H) -> Adapter<H> {
| ------- required by this bound in `handler`
|
= help: the trait `Sync` is not implemented for `dyn Future<Output = std::result::Result<ListTablesOutput, RusotoError<ListTablesError>>> + Send`
note: future is not `Sync` as it awaits another future which is not `Sync`
--> src/main.rs:23:18
|
23 | let output = client.list_tables(Default::default()).await?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ await occurs here on type `Pin<Box<dyn Future<Output = std::result::Result<ListTablesOutput, RusotoError<ListTablesError>>> + Send>>`, which is not `Sync`
Metadata
Metadata
Assignees
Labels
No labels