This is a pure Rust crate for communicating with the AWS IoT Greengrass nucleus runtime.
It uses tokio
for async I/O and this means that currently it is tokio-specific.
While the low-level message (de)serialization and connection API is provided, it is recommended to
use the high-level IpcClient
struct for most use cases.
use greengrass_sdk::{IpcClient, LifecycleState, Result};
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
// Connect to the nucleus runtime.
let mut client = IpcClient::from_env().await?;
// You only want to do this if nucleus is not directly managing the lifecycle of your component.
client.update_state(LifecycleState::Running).await?;
client.pause_component_update().await?;
// Do some work that should not be interrupted by component updates.
client.resume_component_update().await?;
Ok(())
}
Note: The IpcClient::from_env
method used in the example above, requires SVCUID
and
AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT
environment variables to be set
appropriately. The nucleus runtime sets them for components it launches directly.
The low-level API is complete but the high-level API currently only addresses the most common use cases. PRs to add more functionality are most welcome.
This project is licensed under the MIT license.