眠れない夜にjqでパズルをしたのでメモに残す。 ついでに使いたかったが使う機会がなかったTask(go-task)を使うようにした。
インストールと補完が効くような設定は👇
補完が便利。 gyazo.com
AWS CLIのコマンドに関しては 👇 awscli.amazonaws.com
version: '3' tasks: describe-ec2-instances: desc: Describe All EC2 Instances cmds: - aws ec2 describe-instances --profile work | jq -r ".Reservations[].Instances[] | [.Tags[].Value, .InstanceId, .PublicIpAddress, .State.Name] | @csv" describe-status-ec2-instance: desc: Describe Status Of EC2 Instance internal: true cmds: - aws ec2 describe-instances --profile work | jq --arg TAG "${TAG}" -r '.Reservations[].Instances[] | select(.Tags[].Value == "{{.TAG}}").State.Name' requires: vars: [TAG] start-ec2-instance: desc: Start EC2 Instance internal: true cmds: - aws ec2 start-instances --instance-ids {{.INSTANCE_ID}} --profile work vars: INSTANCE_ID: sh: aws ec2 describe-instances --profile work | jq --arg TAG "${TAG}" -r '.Reservations[].Instances[] | select(.Tags[].Value == "{{.TAG}}").InstanceId' requires: vars: [TAG] stop-ec2-instance: desc: Stop EC2 Instance internal: true cmds: - aws ec2 stop-instances --instance-ids {{.INSTANCE_ID}} --profile work vars: INSTANCE_ID: sh: aws ec2 describe-instances --profile work | jq --arg TAG "${TAG}" -r '.Reservations[].Instances[] | select(.Tags[].Value == "{{.TAG}}").InstanceId' requires: vars: [TAG] describe-status-ec2-instance-staging: desc: Describe Status Of Staging EC2 Instance cmds: - task: describe-status-ec2-instance vars: { TAG: "staging-tag" } start-ec2-instance-staging: desc: Start Staging EC2 Instance cmds: - task: start-ec2-instance vars: { TAG: "staging-tag" } stop-ec2-instance-staging: desc: Stop Staging EC2 Instance cmds: - task: stop-ec2-instance vars: { TAG: "staging-tag" }