hakoで、バッチ系の一発処理用のoneshotコマンドを使ってみる。
hakoのバージョンは>= hako-0.20.2
(要Ruby 2.3)
$ ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] $ gem install hako ... Fetching: hako-0.20.2.gem (100%) Successfully installed hako-0.20.2 5 gems installed
まず、例のごとくECSクラスタとEC2インスタンスを準備する。
ecs-cli configure -r ap-northeast-1 -c hello-hako-oneshot
ecs-cli up \ --keypair winebarrel \ --capability-iam \ --vpc vpc-... \ --subnets subnet-... \ --security-group sg-... \ --instance-type m4.large
おけ。
ログ出力用CloudWatch LogsにLogGroupを作っておく。
aws logs create-log-group --log-group-name my-logs
hakoのyamlは以下のような感じ。
- hello.yml
scheduler: type: ecs region: ap-northeast-1 cluster: hello-hako-oneshot desired_count: 1 app: image: busybox memory: 128 log_configuration: log_driver: awslogs options: awslogs-group: my-logs awslogs-region: ap-northeast-1 awslogs-stream-prefix: example
実行してみる。
$ hako oneshot hello.yml echo hello I, [2016-09-15T21:19:19.668005 #50187] INFO -- : Registered task definition: arn:aws:ecs:ap-northeast-1:822997939312:task-definition/hello-oneshot:2 I, [2016-09-15T21:19:19.795313 #50187] INFO -- : Started task: arn:aws:ecs:ap-northeast-1:822997939312:task/008875de-41d1-49ea-88c9-29ea1270384e I, [2016-09-15T21:19:20.880933 #50187] INFO -- : Container instance is arn:aws:ecs:ap-northeast-1:822997939312:container-instance/71b35bd6-6d06-486a-955a-6dd24b2ca1ec (ECS Instance - amazon-ecs-cli-setup-hello-hako-oneshot i-0a295d5b1ff678c4f) I, [2016-09-15T21:19:24.158628 #50187] INFO -- : Started at 2016-09-15 21:19:23 +0900 I, [2016-09-15T21:19:24.158756 #50187] INFO -- : Stopped at 2016-09-15 21:19:23 +0900 (reason: Essential container in task exited) I, [2016-09-15T21:19:24.158802 #50187] INFO -- : Oneshot task finished I, [2016-09-15T21:19:24.158840 #50187] INFO -- : app has stopped with exit_code=0
ログを見てみる。
おけおけ。