async fn put_item(
    client: &Client,
    table_name: &str,
    request: Request,
) -> Result<impl IntoResponse, Error> {
    // Extract path parameter from request
    let path_parameters = request.path_parameters();
    let id = match path_parameters.first("id") {
        Some(id) => id,
        None => return Ok(Response::builder().status(400).body("id is required")?),
    };

    // Extract body from request
    let body = match request.body() {
        Body::Empty => "".to_string(),
        Body::Text(body) => body.clone(),
        Body::Binary(body) => String::from_utf8_lossy(body).to_string(),
    };

    // Put the item in the DynamoDB table
    let res = client
        .put_item()
        .table_name(table_name)
        .item("id", AttributeValue::S(id.to_string()))
        .item("payload", AttributeValue::S(body))
        .send()
        .await;

    // Return a response to the end-user
    match res {
        Ok(_) => Ok(Response::builder().status(200).body("item saved")?),
        Err(_) => Ok(Response::builder().status(500).body("internal error")?),
    }
}
/// Put Item Lambda function
///
/// This function will run for every invoke of the Lambda function.
Put Item Lambda function
This function will run for every invoke of the Lambda function.
Put Item Lambda function This function will run for every invoke of the Lambda function .
async fn put_item(
    client: &Client,
    table_name: &str,
    request: Request,
) -> Result<impl IntoResponse, Error> {
    // Extract path parameter from request
    let path_parameters = request.path_parameters();
    let id = match path_parameters.first("id") {
        Some(id) => id,
        None => return Ok(Response::builder().status(400).body("id is required")?),
    };
    // Extract body from request
    let body = match request.body() {
        Body::Empty => "".to_string(),
        Body::Text(body) => body.clone(),
        Body::Binary(body) => String::from_utf8_lossy(body).to_string(),
    };
    // Put the item in the DynamoDB table
    let res = client
        .put_item()
        .table_name(table_name)
        .item("id", AttributeValue::S(id.to_string()))
        .item("payload", AttributeValue::S(body))
        .send()
        .await;
    // Return a response to the end-user
    match res {
        Ok(_) => Ok(Response::builder().status(200).body("item saved")?),
        Err(_) => Ok(Response::builder().status(500).body("internal error")?),
    }
}
async fn put_item ( client : & Client , table_name : & str , request : Request , ) -> Result < impl IntoResponse , Error > { // Extract path parameter from request let path_parameters = request . path_parameters ( ) ; let id = match path_parameters . first ( " " ) { Some ( id ) => id , None => return Ok ( Response :: builder ( ) . status ( 400 ) . body ( " " ) ? ) , } ; // Extract body from request let body = match request . body ( ) { Body :: Empty => " " . to_string ( ) , Body :: Text ( body ) => body . clone ( ) , Body :: Binary ( body ) => String :: from_utf8_lossy ( body ) . to_string ( ) , } ; // Put the item in the DynamoDB table let res = client . put_item ( ) . table_name ( table_name ) . item ( " " , AttributeValue :: S ( id . to_string ( ) ) ) . item ( " " , AttributeValue :: S ( body ) ) . send ( ) . await ; // Return a response to the end-user match res { Ok ( _ ) => Ok ( Response :: builder ( ) . status ( 200 ) . body ( " " ) ? ) , Err ( _ ) => Ok ( Response :: builder ( ) . status ( 500 ) . body ( " " ) ? ) , } }
Put Item Lambda function
This function will run for every invoke of the Lambda function.
Put Item Lambda function This function will run for every invoke of the Lambda function .
client
&Client
table_name
&str
request
Request