ecs-pf
Version:
CLI for port-forwarding to RDS via AWS ECS
64 lines (63 loc) • 2.66 kB
JavaScript
import { displayDryRunResult, generateExecDryRun } from "./core/dry-run.js";
import { messages } from "./utils/index.js";
export async function execECSTask(options) {
if (options.dryRun) {
await execECSTaskDryRun(options);
return;
}
if (!options.region ||
!options.cluster ||
!options.task ||
!options.container) {
messages.error("All required options must be provided for direct execution");
messages.info("Required options: --region, --cluster, --task, --container");
messages.info("Or use 'exec-task-ui' for interactive selection");
throw new Error("Missing required options for direct execution");
}
const command = options.command || "/bin/bash";
messages.info(`Executing command in ECS task container...`);
messages.info(`Region: ${options.region}`);
messages.info(`Cluster: ${options.cluster}`);
messages.info(`Task: ${options.task}`);
messages.info(`Container: ${options.container}`);
messages.info(`Command: ${command}`);
const { executeECSCommand } = await import("./session.js");
await executeECSCommand({
region: options.region,
clusterName: options.cluster,
taskArn: options.task,
containerName: options.container,
command,
});
}
async function execECSTaskDryRun(options) {
if (!options.region ||
!options.cluster ||
!options.task ||
!options.container) {
messages.error("All required options must be provided for dry-run mode");
messages.info("Required options: --region, --cluster, --task, --container");
messages.info("Or use 'exec-task-ui' for interactive selection");
throw new Error("Missing required options for dry-run mode");
}
const command = options.command || "/bin/bash";
messages.info(`ECS task container execution (DRY RUN)...`);
messages.info(`Region: ${options.region}`);
messages.info(`Cluster: ${options.cluster}`);
messages.info(`Task: ${options.task}`);
messages.info(`Container: ${options.container}`);
messages.info(`Command: ${command}`);
const dryRunResult = generateExecDryRun({
region: options.region,
cluster: options.cluster,
task: options.task,
container: options.container,
command,
});
displayDryRunResult(dryRunResult);
messages.success("Dry run completed successfully.");
}
export async function execECSTaskWithSimpleUI(options = { dryRun: false }) {
const { execECSTaskWithSimpleUIInternal } = await import("./core/exec-ui-flow.js");
await execECSTaskWithSimpleUIInternal(options);
}