Skip to content

Commit

Permalink
Check if session-manager-plugin exists sooner
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Dec 19, 2024
1 parent 88bd863 commit f15a4c0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ var execCmd = &cobra.Command{
env AWS_PROFILE=<profile> iecs exec
`,
Run: func(cmd *cobra.Command, args []string) {
smpPath, err := exec.LookPath("session-manager-plugin")
if err != nil {
panic(err)
}
clusterId, err := cmd.Flags().GetString(execClusterFlag)
if err != nil {
panic(err)
Expand Down Expand Up @@ -61,15 +65,15 @@ var execCmd = &cobra.Command{
panic(err)
}
client := ecs.NewFromConfig(cfg)
err = runExec(context.TODO(), client, cfg.Region, clusterId, serviceId, taskId, containerId, command, interactive)
err = runExec(context.TODO(), smpPath, client, cfg.Region, clusterId, serviceId, taskId, containerId, command, interactive)
if err != nil {
panic(err)
}
},
Aliases: []string{"ssh"},
}

func runExec(ctx context.Context, client *ecs.Client, region string, clusterId string, serviceId string, taskId string, containerId string, command string, interactive bool) error {
func runExec(ctx context.Context, smpPath string, client *ecs.Client, region string, clusterId string, serviceId string, taskId string, containerId string, command string, interactive bool) error {
defaultSelector := &selector.DefaultSelector{}
cluster, err := selector.SelectCluster(ctx, client, defaultSelector, clusterId)
if err != nil {
Expand Down Expand Up @@ -114,7 +118,7 @@ func runExec(ctx context.Context, client *ecs.Client, region string, clusterId s
return err
}
// https://github.com/aws/aws-cli/blob/develop/awscli/customizations/ecs/executecommand.py
smp := exec.Command("session-manager-plugin",
smp := exec.Command(smpPath,
string(session),
region,
"StartSession",
Expand Down

0 comments on commit f15a4c0

Please sign in to comment.