-
Notifications
You must be signed in to change notification settings - Fork 361
The example code does not work #254
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
Comments
If you describe in cargo.toml as follows, it was done. lambda = { git = "https://github.com/awslabs/aws-lambda-rust-runtime/", branch = "master"} |
@nabezokodaikon, sorry we had to put you through this. The official crate is a bit out of date. Can you try using this reference to help us test the latest version?
It relates to PR #244 and has some major improvements, including better error handling. Any feedback or questions are welcome. |
Thank you response. On that branch, I got the following error.
Can not because the My code is below. use lambda::{handler_fn, Context};
use log::error;
use rusoto_core::Region;
use rusoto_dynamodb::{
AttributeValue, DeleteItemInput, DynamoDb, DynamoDbClient, GetItemInput, PutItemInput,
UpdateItemInput,
};
use serde_derive::{Deserialize, Serialize};
use simple_error::bail;
use std::collections::HashMap;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
#[derive(Deserialize)]
struct CustonEvent {
name: String,
}
#[derive(Serialize)]
struct CustomOutput {
message: String,
}
async fn put(e: CustonEvent) -> Result<CustomOutput, Error> {
let mut create_key: HashMap<String, AttributeValue> = HashMap::new();
create_key.insert(
String::from("user_id"),
AttributeValue {
s: Some(e.name),
..Default::default()
},
);
create_key.insert(
String::from("timestamp"),
AttributeValue {
n: Some(1.to_string()),
..Default::default()
},
);
create_key.insert(
String::from("comment"),
AttributeValue {
s: Some("本日は雨なり".to_string()),
..Default::default()
},
);
create_key.insert(
String::from("state"),
AttributeValue {
n: Some(3.to_string()),
..Default::default()
},
);
let create_serials = PutItemInput {
table_name: String::from("ywt-table"),
item: create_key,
..Default::default()
};
let client = DynamoDbClient::new(Region::UsEast1);
match client.put_item(create_serials).await {
Ok(result) => match result.attributes {
Some(_) => println!("some"),
None => println!("none"),
},
Err(error) => {
panic!("Error: {:?}", error);
}
};
Ok(CustomOutput {
message: format!("Success"),
})
}
async fn my_handler(e: CustonEvent, c: Context) -> Result<CustomOutput, Error> {
if e.name == "" {
error!("Empty request_id in request {}", c.request_id);
bail!("Empty request_id in request");
}
put(e).await
}
#[tokio::main]
async fn main() -> Result<(), Error> {
simple_logger::init_with_level(log::Level::Debug)?;
lambda::run(handler_fn(my_handler)).await?;
Ok(())
} |
Yeah, I got that too. Fixed. Will push in 2 hrs. Thanks for trying! Much
appreciated.
…On Wed, 19 Aug 2020, 18:13 nabezokodaikon, ***@***.***> wrote:
Thank you response.
On that branch, I got the following error.
error: future cannot be shared between threads safely
--> src/main.rs:92:5
|
92 | lambda::run(handler_fn(my_handler)).await?;
| ^^^^^^^^^^^ future returned by `my_handler` is not `Sync`
|
= help: the trait `std::marker::Sync` is not implemented for `dyn std::future::Future<Output = std::result::Result<rusoto_dynamodb::generated::PutItemOutput, rusoto_core::error::RusotoError<rusoto_dynamodb::generated::PutItemError>>> + std::marker::Send`
note: future is not `Sync` as it awaits another future which is not `Sync`
--> src/main.rs:65:11
|
65 | match client.put_item(create_serials).await {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ await occurs here on type `std::pin::Pin<std::boxed::Box<dyn std::future::Future<Output = std::result::Result<rusoto_dynamodb::generated::PutItemOutput, rusoto_core::error::RusotoError<rusoto_dynamodb::generated::PutItemError>>> + std::marker::Send>>`, which is not `Sync`
Can not because the client.put_item is the await even though the
lambda::run function is seeking the synchronization function.
My code is below.
use lambda::{handler_fn, Context};
use log::error;
use rusoto_core::Region;
use rusoto_dynamodb::{
AttributeValue, DeleteItemInput, DynamoDb, DynamoDbClient, GetItemInput, PutItemInput,
UpdateItemInput,
};
use serde_derive::{Deserialize, Serialize};
use simple_error::bail;
use std::collections::HashMap;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
#[derive(Deserialize)]
struct CustonEvent {
name: String,
}
#[derive(Serialize)]
struct CustomOutput {
message: String,
}
async fn put(e: CustonEvent) -> Result<CustomOutput, Error> {
let mut create_key: HashMap<String, AttributeValue> = HashMap::new();
create_key.insert(
String::from("user_id"),
AttributeValue {
s: Some(e.name),
..Default::default()
},
);
create_key.insert(
String::from("timestamp"),
AttributeValue {
n: Some(1.to_string()),
..Default::default()
},
);
create_key.insert(
String::from("comment"),
AttributeValue {
s: Some("本日は雨なり".to_string()),
..Default::default()
},
);
create_key.insert(
String::from("state"),
AttributeValue {
n: Some(3.to_string()),
..Default::default()
},
);
let create_serials = PutItemInput {
table_name: String::from("ywt-table"),
item: create_key,
..Default::default()
};
let client = DynamoDbClient::new(Region::UsEast1);
match client.put_item(create_serials).await {
Ok(result) => match result.attributes {
Some(_) => println!("some"),
None => println!("none"),
},
Err(error) => {
panic!("Error: {:?}", error);
}
};
Ok(CustomOutput {
message: format!("Success"),
})
}
async fn my_handler(e: CustonEvent, c: Context) -> Result<CustomOutput, Error> {
if e.name == "" {
error!("Empty request_id in request {}", c.request_id);
bail!("Empty request_id in request");
}
put(e).await
}
#[tokio::main]
async fn main() -> Result<(), Error> {
simple_logger::init_with_level(log::Level::Debug)?;
lambda::run(handler_fn(my_handler)).await?;
Ok(())
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#254 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABNGZDHLWBJWMEDGYODOCGDSBNUSLANCNFSM4QDZHSAA>
.
|
@nabezokodaikon, I fixed that bug. The same branch should work OK now. I'll be on standby if there are any other problems. |
I confirmed that it works normally. Thank you. |
An error occurs in the top
use lambda::{handler_fn, Context};
ofhello-without-macro.rs
.aws-lambda-rust-runtime/lambda/examples/hello-without-macro.rs
Line 1 in a9de2fc
The error details are as follows.
I am adding
lambda_runtime = "0.2.1"
to Cargo.toml's [dependencies].The text was updated successfully, but these errors were encountered: