88 "github.com/aws/aws-sdk-go-v2/config"
99 "github.com/aws/aws-sdk-go-v2/service/ecs"
1010 "github.com/fujiwara/ecsta"
11+ "os"
1112)
1213
1314var sessionInstance * ecs.Client
@@ -22,14 +23,16 @@ func InitAWS(profile string) error {
2223 if err != nil {
2324 return fmt .Errorf ("failed to load configuration: %w" , err )
2425 }
26+ os .Setenv ("AWS_PROFILE" , profile ) //required for aws sdk
2527 sessionInstance = ecs .NewFromConfig (cfg )
2628 sessionConfig = cfg // Save session configuration
2729 }
2830 return nil
2931}
3032
3133// ExecFargate executes a command in a specified container on an ECS Fargate service
32- func ExecFargate (profile , cluster , service , containerName , command string ) error {
34+ func ExecFargate (profile , cluster , command string ) error {
35+
3336 if err := InitAWS (profile ); err != nil {
3437 return fmt .Errorf ("failed to initialize AWS session: %w" , err )
3538 }
@@ -39,15 +42,13 @@ func ExecFargate(profile, cluster, service, containerName, command string) error
3942 if err != nil {
4043 return fmt .Errorf ("failed to create ecsta application: %w" , err )
4144 }
42- service = "app"
4345
4446 entrypoint := "/usr/bin/ssm-parent"
4547 configPath := "/app/.ssm-parent.yaml"
4648 fullCommand := fmt .Sprintf ("%s -c %s run -- %s" , entrypoint , configPath , command )
4749 execOpt := ecsta.ExecOption {
4850 Command : fullCommand ,
4951 }
50- fmt .Println (execOpt )
5152 if err := ecstaApp .RunExec (context .Background (), & execOpt ); err != nil {
5253 return fmt .Errorf ("failed to execute command: %w" , err )
5354 }
0 commit comments