diff --git a/rust/iecs/Cargo.lock b/rust/iecs/Cargo.lock index 55e76de..f4a0602 100644 --- a/rust/iecs/Cargo.lock +++ b/rust/iecs/Cargo.lock @@ -145,6 +145,29 @@ dependencies = [ "uuid", ] +[[package]] +name = "aws-sdk-cloudwatchlogs" +version = "1.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d59340973410bfadb6091a3823c7d23dbb1359216f6b8212a9a248ef13d2f79" +dependencies = [ + "aws-credential-types", + "aws-runtime", + "aws-smithy-async", + "aws-smithy-http", + "aws-smithy-json", + "aws-smithy-runtime", + "aws-smithy-runtime-api", + "aws-smithy-types", + "aws-types", + "bytes", + "fastrand", + "http 0.2.12", + "once_cell", + "regex-lite", + "tracing", +] + [[package]] name = "aws-sdk-ecs" version = "1.45.0" @@ -333,9 +356,9 @@ dependencies = [ [[package]] name = "aws-smithy-runtime" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1ce695746394772e7000b39fe073095db6d45a862d0767dd5ad0ac0d7f8eb87" +checksum = "a065c0fe6fdbdf9f11817eb68582b2ab4aff9e9c39e986ae48f7ec576c6322db" dependencies = [ "aws-smithy-async", "aws-smithy-http", @@ -938,6 +961,7 @@ version = "0.1.0" dependencies = [ "anyhow", "aws-config", + "aws-sdk-cloudwatchlogs", "aws-sdk-ecs", "aws-sdk-ssm", "clap", diff --git a/rust/iecs/Cargo.toml b/rust/iecs/Cargo.toml index f3f07cb..c74bfca 100644 --- a/rust/iecs/Cargo.toml +++ b/rust/iecs/Cargo.toml @@ -10,6 +10,7 @@ rust-version = "1.81" [dependencies] anyhow = "1.0.89" aws-config = "1.5.6" +aws-sdk-cloudwatchlogs = "1.52.0" aws-sdk-ecs = "1.45.0" aws-sdk-ssm = "1.49.0" clap = { version = "4.5.17", features = ["derive"] } diff --git a/rust/iecs/src/main.rs b/rust/iecs/src/main.rs index 16b63bf..baeab45 100644 --- a/rust/iecs/src/main.rs +++ b/rust/iecs/src/main.rs @@ -185,20 +185,23 @@ impl Serialize for SerializableStartSession { #[tokio::main] async fn main() -> anyhow::Result<()> { let config = aws_config::defaults(BehaviorVersion::latest()).load().await; - let client = aws_sdk_ecs::Client::new(&config); + let ecs_client = aws_sdk_ecs::Client::new(&config); match Cli::parse() { - Cli::Exec(args) => run_exec(&client, &args).await, - Cli::Logs(args) => run_logs(&client, &args).await, + Cli::Exec(args) => run_exec(&ecs_client, &args).await, + Cli::Logs(args) => { + let cw_logs_client = aws_sdk_cloudwatchlogs::Client::new(&config); + run_logs(&ecs_client, &cw_logs_client, &args).await + } } } -async fn run_exec(client: &aws_sdk_ecs::Client, args: &ExecArgs) -> anyhow::Result<()> { - let cluster = get_cluster(&client, &args.cluster).await?; - let task = get_task(&client, &cluster.arn, &args.task).await?; - let container = get_container(&client, &cluster.arn, &task.arn, &args.container).await?; +async fn run_exec(ecs_client: &aws_sdk_ecs::Client, args: &ExecArgs) -> anyhow::Result<()> { + 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?; let session = execute_command( - &client, + &ecs_client, &cluster.arn, &task.arn, &container.name, @@ -216,7 +219,7 @@ async fn run_exec(client: &aws_sdk_ecs::Client, args: &ExecArgs) -> anyhow::Resu .build()?, ); - let region = client.config().region().context("Region not found")?; + let region = ecs_client.config().region().context("Region not found")?; let mut command = Command::new("session-manager-plugin") .args([ @@ -234,14 +237,18 @@ async fn run_exec(client: &aws_sdk_ecs::Client, args: &ExecArgs) -> anyhow::Resu Ok(()) } -async fn run_logs(client: &aws_sdk_ecs::Client, args: &LogsArgs) -> anyhow::Result<()> { - let cluster = get_cluster(&client, &args.cluster).await?; - let task = get_task(&client, &cluster.arn, &args.task).await?; +async fn run_logs( + ecs_client: &aws_sdk_ecs::Client, + cw_logs_client: &aws_sdk_cloudwatchlogs::Client, + args: &LogsArgs, +) -> anyhow::Result<()> { + let cluster = get_cluster(&ecs_client, &args.cluster).await?; + let task = get_task(&ecs_client, &cluster.arn, &args.task).await?; let task_definition_arn = task .task_definition_arn .context("task_definition_arn not found")?; // let container = get_container(&client, &cluster.arn, &task.arn, &args.container).await?; - let output = client + let output = ecs_client .describe_task_definition() .task_definition(task_definition_arn) .send()