Giter VIP home page Giter VIP logo

ecs-fargate-oneshot's Introduction

ci

ecs-fargate-oneshot

Executes oneshot task on ECS (fargate)

Installation

Download binary by installation script

# if you would like install to /usr/local/bin
$ curl -sSfL https://raw.githubusercontent.com/shufo/ecs-fargate-oneshot/master/install.sh  | sudo sh -s - -b /usr/local/bin

# this will install $GOPATH/.bin/ecs-fargate-oneshot or ./bin/ecs-fargate-oneshot
$ curl -sSfL https://raw.githubusercontent.com/shufo/ecs-fargate-oneshot/master/install.sh  | sh -s

or using go get

$ go get -u github.com/shufo/ecs-fargate-oneshot

resource permissions

You must have these IAM permissions to execute tasks

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ExecuteOneShotTask",
      "Effect": "Allow",
      "Action": [
        "ecs:DescribeServices",
        "ecs:DescribeTasks",
        "ecs:DescribeTaskDefinition",
        "ecs:RunTask",
        "ecs:ListTaskDefinitions",
        "logs:GetLogEvents"
      ],
      "Resource": "*"
    }
  ]
}

Usage

This command takes global option and sub command options

ecs-fargate-oneshot [options] run|logs [sub command options]

Executes tasks

You can launch tasks with run sub command

$ ecs-fargate-oneshot -v \
    --cluster cluster-name \
    --service service-name \
    run --task-definition app \
    --container app \
    --show-cloudwatch-logs \
    --cpu 256 \
    --memory 512 \
    echo "foo bar"
# output =>
INFO[0001] executing tasks...
Please wait for tasks to finished
INFO[0061] INFO: task finished
INFO[0061] INFO: taskId:  db049581-f47b-4e9e-9d8f-53efa9ee24d0
Event messages for stream app/app/db049581-f47b-4e9e-9d8f-53efa9ee24d0 in log group LOG-GROUP-NAME: /fargate/service/app
   foo bar
db049581-f47b-4e9e-9d8f-53efa9ee24d0

NOTE: If you would like to show logs, you must define log configuration for cloudwatch logs on ecs task definition.

...
"logConfiguration": {
    "logDriver": "awslogs",
    "options": {
        "awslogs-group" : "/fargate/service/app",
        "awslogs-region": "us-east-1",
        "awslogs-stream-prefix": "app"
    }
}

or if you would not require logs

$ ecs-fargate-oneshot \
    --cluster cluster-name \
    --service service-name \
    run --task-definition app \
    --container app \
    echo "foo bar"

logs

You can showing logs after task execution by logs sub command

# run task without logs
$ ecs-fargate-oneshot \
    --cluster cluster-name \
    --service service-name \
    run --task-definition app \
    --container app \
    echo "foo bar"
# output =>
287771bd-92f4-407c-870f-7a480b94cbc7 # this is taskId

# show up logs by passing task id from execution output
$ ecs-fargate-oneshot \
    --cluster cluster-name \
    --service service-name \
    logs --container app \
    287771bd-92f4-407c-870f-7a480b94cbc7
# output =>
Event messages for stream app/app/287771bd-92f4-407c-870f-7a480b94cbc7 in log group LOG-GROUP-NAME: /fargat
e/service/service-name
   foo bar

# or you can pass the task id from stdin
$ ecs-fargate-oneshot --cluster cluster-name --service service-name run --task-definition app --container app echo "foo bar" | ecs-fargate-oneshot --cluster cluster-name --service service-name logs --container app

Options

Global

option description default required
--cluster, -c Cluster name "" yes
--service, -s Service name "" yes
--verbose, -v Show verbose logs false no
--progress, -p Show progress false no
--help,, -h Show help false no

run sub command

option description default required
--task-definition, -t Task definition name "" yes
--container, -n Container name "" yes
--cpu, -C The number of cpu units reserved for the container, instead of the default value from the task definition Task definition's default no
--memory, -m The hard limit (in MiB) of memory to present to the container, instead of the default value from the task definition Task definition's default no
--show-cloudwatch-logs,, -l Show logs on cloudwatch logs false no

logs sub command

option description default required
--container, -n Container name "" yes
--task-id, -t An ECS task id "" no

Troubleshoot

  • If you encounter the error about the aws API execution

check if the aws environment variable is properly set

$ env | grep aws -i

export AWS_DEFAULT_REGION=
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=

TODO

  • Add option to execute tasks without waiting task status
  • Add option for tab width for logs

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Testing

$ go test -v ./...

Development

$ GO111MODULE=off go get github.com/oxequa/realize
$ realize start
$ ./app <option> <args>

LICENSE

MIT

ecs-fargate-oneshot's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar renovate[bot] avatar shufo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dzubchik hilenko

ecs-fargate-oneshot's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
dockerfile
Dockerfile
  • shufo/go-graphql-base 1.14
github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/cache v3
  • actions/setup-go v5
.github/workflows/release-please.yml
  • google-github-actions/release-please-action v3
  • actions/checkout v4
  • actions/setup-go v5
  • goreleaser/goreleaser-action v5
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-go v5
  • goreleaser/goreleaser-action v5
gomod
go.mod
  • go 1.17
  • github.com/aws/aws-sdk-go v1.47.3
  • github.com/briandowns/spinner v1.21.0
  • github.com/sirupsen/logrus v1.9.3
  • github.com/urfave/cli/v2 v2.24.3

  • Check this box to trigger a request for Renovate to run again on this repository

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

github.com/shufo/ecs-fargate-oneshot/logs: cannot find module providing package github.com/shufo/ecs-fargate-oneshot/logs
github.com/shufo/ecs-fargate-oneshot imports
	github.com/shufo/ecs-fargate-oneshot/tasks: cannot find module providing package github.com/shufo/ecs-fargate-oneshot/tasks

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Dependabot can't resolve your Go dependency files

Dependabot can't resolve your Go dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

github.com/shufo/ecs-fargate-oneshot/logs: cannot find module providing package github.com/shufo/ecs-fargate-oneshot/logs
	github.com/shufo/ecs-fargate-oneshot/tasks: cannot find module providing package github.com/shufo/ecs-fargate-oneshot/tasks

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.