ecsrun

command module
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 1 Imported by: 0

README

ecsrun

Go Report Card GitHub Workflow Status Release

Easily run one-off tasks against an ECS Task Definition 🐳

Purpose

ecsrun is a small go CLI app to provide a config file based approach to executing one-off ECS Tasks. The ECS RunTask command is a pain to write out on the command line, so this tool provides an easy way to wrap any common RunTask executions you do in a simple yaml file.

Install

From Homebrew
brew install masterpointio/tap/ecsrun
From Go Get
go get -u github.com/masterpointio/ecsrun

Usage

Invoking with ecsrun.yaml (easiest)

Given you have an ecsrun.yaml like so:

default: &default
  cluster: mp-test-cluster
  task: mp-test-alpine
  security-group: sg-06c65c3206401917e
  subnet: subnet-0c97e16b8a52b4b86
  public: false
  cmd:
    - bash
    - -c
    - echo
    - "hello world"

migrate:
  <<: *default
  task: mp-test-django
  cmd:
    - python
    - ./manage.py
    - migrate

You can invoke two easy commands to spin up a one-off task:

# Invoke the 'mp-test-alpine' task definition with the 'hello world' `CMD`
ecsrun

# Invoke the 'mp-test-django' task definition with the `manage.py migrate` `CMD`
ecsrun --config migrate
From Command Line

ecsrun supports all of the config options via CLI arguments as well:

ecsrun --cluster mp-example-task-runner \
       --subnet subnet-0c97e16b8a52b4b86 \
       --security-group sg-06c65c3206401917e \
       --cmd "bash,-c,echo,\"Hello world\"" \
       --region us-west-2 \
       --public \
       --verbose

You can use this in combination with a configuration file to only override certain arguments:

ecsrun --config migrate
       --subnet ${DIFFERENT_SUBNET} \
       --public
From Environment Variables

You can also pass configuration to ecsrun via environment variables:

export AWS_PROFILE="mp-gowiem"
export AWS_ACCESS_KEY_ID="123"
export AWS_SECRET_ACCESS_KEY="SECRET123"
export ECSRUN_CMD="bash,-c,echo,\"Hello world\""
export ECSRUN_CLUSTER="mp-testing-cluster"
export ECSRUN_TASK="mp-testing-task"
export ECSRUN_SECURITY_GROUP="sg-06c65c3206401917e"
export ECSRUN_SUBNET="subnet-0c97e16b8a52b4b86"
export ECSRUN_VERBOSE="true"

# Invoke a dry run to check the resulting `RunTaskInput` configuration
ecsrun --dry-run
Initialize an empty ecsrun.yaml

Don't have an ecsrun.yaml file yet? Initialize the scaffold of one in your current directory:

ecsrun init
More

Be sure to check out ecsrun help for more info and full configuration options.

Inspiration

I wrote the included run_command bash script for a client project as admin tasks were quite common on the project (migrations, django manage.py jobs, debugging, etc). This script was pretty ugly (what bash script isn't honestly), but it got the job done. I wanted to build a new project in golang to try out the langauge, and converting run_command to something with a bit more grace seemed like a fun project. ecsrun is the result!

Roadmap

  • Support basic CLI usage
  • Support local config file
  • Support --dryrun Flag
  • Add more tests
  • Add a ecsrun init command to generate the ecsrun.yml config file.
  • Support log group / stream tailing of initiated task
  • Support selection of resources similar to gossm (cluster, task def, task def revision, etc etc)
  • Support validation of given params: cluster, definition name, revision, subnet ID, SG ID, ect.
  • Support EC2 usage.

Documentation

Overview

Copyright © 2020 Matt Gowie <matt@masterpoint.io>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL