Skip to content

Commit

Permalink
Check if session-manager-plugin exists
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Oct 31, 2024
1 parent c231bea commit cdbac86
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
57 changes: 57 additions & 0 deletions rust/iecs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/iecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ inquire = "0.7.5"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
tokio = { version = "1.40.0", features = ["full"] }
which = "6.0.3"
14 changes: 12 additions & 2 deletions rust/iecs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ use aws_sdk_ssm::operation::start_session::StartSessionInput;
use clap::Parser;
use inquire::Select;
use serde::{ser::SerializeStruct, Serialize};
use which::which;

static SESSION_MANAGER_PLUGIN_NOT_FOUND: &str = r#"
'session-manager-plugin' not found, install it using the instructions in the link below:
https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html
"#;

#[derive(Parser)]
#[command(name = "iecs")]
Expand Down Expand Up @@ -196,6 +203,9 @@ async fn main() -> anyhow::Result<()> {
}

async fn run_exec(ecs_client: &aws_sdk_ecs::Client, args: &ExecArgs) -> anyhow::Result<()> {
let session_manager_path =
which("session-manager-plugin").context(SESSION_MANAGER_PLUGIN_NOT_FOUND)?;

let cluster = get_cluster(&ecs_client, &args.cluster).await?;
let task = get_task(&ecs_client, &cluster.arn, &args.task).await?;
let container = get_container(&ecs_client, &cluster.arn, &task.arn, &args.container).await?;
Expand All @@ -221,7 +231,7 @@ async fn run_exec(ecs_client: &aws_sdk_ecs::Client, args: &ExecArgs) -> anyhow::

let region = ecs_client.config().region().context("Region not found")?;

let mut command = Command::new("session-manager-plugin")
let mut command = Command::new(session_manager_path)
.args([
serde_json::to_string(&session)?,
region.to_string(),
Expand Down Expand Up @@ -257,7 +267,7 @@ async fn run_logs(
.task_definition
.context("TODO")?
.container_definitions
.context("")?
.context("TODO")?
.into_iter()
// TODO: remove hard-coded container name
.find(|container_definition| container_definition.name == Some("action_cable".to_string()))
Expand Down

0 comments on commit cdbac86

Please sign in to comment.