DEV Community

Atsushi Miyamoto
Atsushi Miyamoto

Posted on

Execute ECS task by ecsta

Are you tired of debugging when you use an ECS? If so, ecsta is a tool for you!
ecsta is to help you execute the ECS container by cmd.

What is ecsta?

ecsta is a tool that you can use to execute your ecs tasks, such as describing, listing, and even port forwarding your ecs task easily.

fujiwara/ecsta: ECS Task Assistant tool.

Features

  • list tasks
  • describe task
  • exec task
  • portforward task
  • stop task
  • trace task
  • logs
Usage: ecsta <command>

Flags:
  -h, --help                        Show context-sensitive help.
  -c, --cluster=STRING              ECS cluster name ($ECS_CLUSTER)
  -r, --region=STRING               AWS region ($AWS_REGION)
  -o, --output="table"              output format (table, tsv, json) ($ECSTA_OUTPUT)
  -q, --task-format-query=STRING    A jq query to format task in selector
                                    ($ECSTA_TASK_FORMAT_QUERY)

Commands:
  configure
    Create a configuration file of ecsta

  describe
    Describe tasks

  exec
    Execute a command on a task

  list
    List tasks

  logs
    Show log messages of a task

  portforward --local-port=INT --remote-port=INT
    Forward a port of a task

  stop
    Stop a task

  trace
    Trace a task

  version
    Show version
Enter fullscreen mode Exit fullscreen mode

How to use?

I will show you some features

NOTE: you need to set your aws credential (~/.aws/credentials)

Install

brew install fujiwara/tap/ecsta
Enter fullscreen mode Exit fullscreen mode

List task

ecsta list -c cluster-name -s service-name

|                ID                | TASKDEFINITION  | INSTANCE | LASTSTATUS | DESIREDSTATUS |         CREATEDAT         |         GROUP         |  TYPE   |
+----------------------------------+-----------------+----------+------------+---------------+
| 12e1e24342a6bddddbf148393ab6e4cf3 | task-definition:1 |          | RUNNING    | RUNNING       | 2023-03-16T00:00:00+09:00 | service:service-name | FARGATE |
Enter fullscreen mode Exit fullscreen mode

Exec task

This command is wrapper of ECS Exec

ecsta exec --service=service-name --container=container-name

Enter cluster name: cluster-name
Enter task ID: 12e1e24342a6bddddbf148393ab6e4cf3

Starting session with SessionId: ecs-execute-command-0dvv124623eaaf0f
/api #

Enter fullscreen mode Exit fullscreen mode

Conclusion

This tool is quite helpful to exec your ecs task!

Thank you for reading my article, Happy Coding!

Reference:

Using Amazon ECS Exec for debugging - Amazon ECS

fujiwara/ecsta: ECS Task Assistant tool.

Top comments (0)