h3poteto/ecs-task


Run a task on Amazon ECS and stream the output to stdout

License: MIT

Language: Go

Keywords: cloudwatch-logs, ecs, ecs-task, golang


Build GitHub release GoDoc Renovate

ecs-task

ecs-task is a command line tool to run a task on the ECS. The feature is

  • Wait for completion of the task execution
  • Get logs from CloudWatch Logs and output in stream

This is a command line tool, but you can use task as a package. So when you write own task execition script for AWS ECS, you can embed task package in your golang source code and customize task recipe. Please check godoc.

Install

Get binary from GitHub:

$ wget https://github.com/h3poteto/ecs-task/releases/download/v0.2.1/ecs-task_v0.2.1_linux_amd64.zip
$ unzip ecs-task_v0.2.1_linux_amd64.zip
$ ./ecs-task help
Run a task on ECS

Usage:
  ecs-task [command]

Available Commands:
  help        Help about any command
  run         Run a task on ECS
  version     Print the version number

Flags:
  -h, --help             help for ecs-task
      --profile string   AWS profile (detault is none, and use environment variables)
      --region string    AWS region (default is none, and use AWS_DEFAULT_REGION)
  -v, --verbose          Enable verbose mode

Use "ecs-task [command] --help" for more information about a command.

Usage

Please provide a command to --command.

$ ./ecs-task run --cluster=base-default-prd --container=task --task-definition=fascia-web-prd-task --command="echo 'hoge'" --region=ap-northeast-1
[2018-11-10 19:13:15  0900 JST] hoge

And if the command is failed on ECS, ecs-task exit with error.

$ ./ecs-task run --cluster=base-default-prd --container=task --task-definition=fascia-web-prd-task --command="hoge" --region=ap-northeast-1
[2018-11-10 18:29:24  0900 JST] ./entrypoint.sh: exec: line 13: hoge: not found
FATA[0015] exit code: 127
exit status 1
$ echo $?
1

If you want to run the task as Fargate, please provide fargate flag and your subnet IDs.

$ ./ecs-task run --cluster=base-default-prd --container=task --task-definition=fascia-web-prd-task --command='echo "hoge"' --fargate=true --subnets='subnet-12easdb,subnet-34asbdf' --region=ap-northeast-1

AWS IAM Policy

Below is a basic IAM Policy required for ecs-task.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowUserToECSTask",
      "Effect": "Allow",
      "Action": [
        "ecs:DescribeTaskDefinition",
        "ecs:RunTask",
        "ecs:DescribeTasks",
        "ecs:ListTasks",
        "logs:DescribeLogStreams",
        "logs:GetLogEvents",
        "iam:PassRole"
      ],
      "Resource": "*"
    }
  ]
}

License

The package is available as open source under the terms of the MIT License.

Project Statistics

Sourcerank 5
Repository Size 238 KB
Stars 27
Forks 11
Watchers 2
Open issues 2
Dependencies 45
Contributors 6
Tags 14
Created
Last updated
Last pushed

Top Contributors See all

AkiraFukushima dependabot-preview[bot] Yonathan Randolph Mend Renovate renovate[bot] Shinichi Ishimura

Packages Referencing this Repo

github.com/h3poteto/ecs-task
Run a task on Amazon ECS and stream the output to stdout
Latest release v0.2.10 - Updated - 27 stars

Recent Tags See all

v0.2.10 August 29, 2024
v0.2.9 August 18, 2024
v0.2.8 May 28, 2022
v0.2.7 December 09, 2021
v0.2.6 March 05, 2021
v0.2.5 February 18, 2021
v0.2.4 January 16, 2020
v0.2.3 November 03, 2019
v0.2.2 February 18, 2019
v0.2.1 December 28, 2018
v0.2.0 December 28, 2018
v0.1.2 November 27, 2018
v0.1.1 November 10, 2018
v0.1.0 November 10, 2018

Something wrong with this page? Make a suggestion

Last synced: 2024-08-30 16:07:07 UTC

Login to resync this repository