Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ check-event-features:
cargo test --package aws_lambda_events --no-default-features --features apigw
cargo test --package aws_lambda_events --no-default-features --features appsync
cargo test --package aws_lambda_events --no-default-features --features autoscaling
cargo test --package aws_lambda_events --no-default-features --features bedrock_agent_runtime
cargo test --package aws_lambda_events --no-default-features --features chime_bot
cargo test --package aws_lambda_events --no-default-features --features clientvpn
cargo test --package aws_lambda_events --no-default-features --features cloudwatch_events
Expand Down
2 changes: 2 additions & 0 deletions lambda-events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ default = [
"apigw",
"appsync",
"autoscaling",
"bedrock_agent_runtime",
"chime_bot",
"clientvpn",
"cloudformation",
Expand Down Expand Up @@ -85,6 +86,7 @@ alb = ["bytes", "http", "http-body", "http-serde", "query_map"]
apigw = ["bytes", "http", "http-body", "http-serde", "query_map"]
appsync = []
autoscaling = ["chrono"]
bedrock_agent_runtime = []
chime_bot = ["chrono"]
clientvpn = []
cloudformation = []
Expand Down
94 changes: 94 additions & 0 deletions lambda-events/src/event/bedrock_agent_runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// The Event sent to Lambda from Agents for Amazon Bedrock.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AgentEvent {
///The version of the message that identifies the format of the event data going into the Lambda function and the expected format of the response from a Lambda function. Amazon Bedrock only supports version 1.0.
pub message_version: String,
///Contains information about the name, ID, alias, and version of the agent that the action group belongs to.
pub agent: Agent,
///The user input for the conversation turn.
pub input_text: String,
/// The unique identifier of the agent session.
pub session_id: String,
/// The name of the action group.
pub action_group: String,
/// The path to the API operation, as defined in the OpenAPI schema.
pub api_path: String,
/// The method of the API operation, as defined in the OpenAPI schema.
pub http_method: String,
/// Contains a list of objects. Each object contains the name, type, and value of a parameter in the API operation, as defined in the OpenAPI schema.
pub parameters: Vec<Parameter>,
/// Contains the request body and its properties, as defined in the OpenAPI schema.
pub request_body: RequestBody,
/// Contains session attributes and their values.
pub session_attributes: HashMap<String, String>,
/// Contains prompt attributes and their values.
pub prompt_session_attributes: HashMap<String, String>,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestBody {
/// Contains the request body and its properties
pub content: HashMap<String, Content>,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Content {
/// The content of the request body
pub properties: Vec<Property>,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Property {
/// The name of the parameter
pub name: String,
/// The type of the parameter
pub r#type: String,
/// The value of the parameter
pub value: String,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Parameter {
/// The name of the parameter
pub name: String,
/// The type of the parameter
pub r#type: String,
/// The value of the parameter
pub value: String,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Agent {
/// The name of the agent.
pub name: String,
/// The unique identifier of the agent.
pub id: String,
/// The alias of the agent.
pub alias: String,
/// The version of the agent.
pub version: String,
}

#[cfg(test)]
mod tests {
use serde_json;

#[test]
#[cfg(feature = "bedrock-agent-runtime")]
fn example_bedrock_agent__runtime_event() {
let data = include!("../../fixtures/example-bedrock-agent-runtime-event.json");
let parsed: AgentEvent = serde_json::from_str(&data).unwrap();
let output: String = serde_json::to_string(&parsed).unwrap();
let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap();
assert_eq!(parsed, reparsed);
}
}
4 changes: 4 additions & 0 deletions lambda-events/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub mod appsync;
#[cfg(feature = "autoscaling")]
pub mod autoscaling;

/// AWS Lambda event definitions for agent for amazon bedrock
#[cfg(feature = "bedrock_agent_runtime")]
pub mod bedrock_agent_runtime;

/// AWS Lambda event definitions for chime_bot.
#[cfg(feature = "chime_bot")]
pub mod chime_bot;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"messageVersion": "1.0",
"agent": {
"name": "AgentName",
"id": "AgentID",
"alias": "AgentAlias",
"version": "AgentVersion"
},
"inputText": "InputText",
"sessionId": "SessionID",
"actionGroup": "ActionGroup",
"apiPath": "/api/path",
"httpMethod": "POST",
"parameters": [
{
"name": "param1",
"type": "string",
"value": "value1"
}
],
"requestBody": {
"content": {
"application/json": {
"properties": [
{
"name": "prop1",
"type": "string",
"value": "value1"
}
]
}
}
},
"sessionAttributes": {
"attr1": "value1"
},
"promptSessionAttributes": {
"promptAttr1": "value1"
}
}