Skip to content

Commit

Permalink
Install aws-sdk-cloudwatchlogs
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Oct 22, 2024
1 parent 812d021 commit c231bea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
28 changes: 26 additions & 2 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 @@ -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"] }
Expand Down
33 changes: 20 additions & 13 deletions rust/iecs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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([
Expand All @@ -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()
Expand Down

0 comments on commit c231bea

Please sign in to comment.