my utility scripts collection for daily use
- shell/ecs_login_by_service_name.sh
- shell/command_bookmarks.sh
- shell/open_github_web.sh
- shell/upload_node_lambda_function.sh
- aws_lambda/stopEc2Instance.js
- cloudfront_signed_cookie
- ruby/mdfile_link_elasticsearch
ecs_login_by_service_name.sh logins you to ECS instance or container by ECS service name.
Logging in to ECS server gets as easy as below.
ecslogin -c ecs_cluster_name ecs_service_name # login to instance
ecslogin -d -c ecs_cluster_name ecs_service_name # login to container
brew tap suhirotaka/utility
brew install ecslogin
Usage:
ecslogin <-c ECS_CLUSTER_NAME> [-f PRIVATE_KEY_FILE_NAME] [-d] <ECS_SERVICE_NAME>
Options:
-c ECS cluster name
-f private key file name (~/.ssh/ecslogin.pem is used by default.)
-d directly login to ECS container
-h print this
It is not an easy thing to login to ECS container of a desired ECS service name, because we need complicated steps to look up which EC2 instance is running specific ECS container. I was so frustrated that I wrote this script.
***
command_bookmarks.sh adds command bookmark functionality to your console.
Bookmarks are saved at ~/.commandBookmarks.
It is helpful to bookmark frequently repeated but difficult-to-type commands.
For example, you can bookmark docker stop $(docker ps --filter name=test* -q)
as following.
cmdbm add 'docker stop $(docker ps --filter name=test* -q)'
cmdbm ls
> 3: docker stop $(docker ps --filter name=test* -q)
cmdbm run 3
brew tap suhirotaka/utility
brew install cmdbm
Usage: cmdbm [<action>] [<options>]
Actions:
add <command> Add command to bookmark
ls List bookmarks with their IDs
edit Edit bookmarks
rm <ID> Delete a bookmark of the specified ID looked up by "ls" action
run <ID> Run a command of the specified ID looked up by "ls" action
Options:
--help Print this
--version Show version
***
open_github_web.sh opens github web page from local repository.
Do you want to see GitHub web when working with console?
You can open repository's web page by open_github_web.sh origin
Usage: open_github_web.sh [<REMOTE_NAME>]
If no REMOTE_NAME is given, "origin" will be used.
Options:
--help Print this
--version Show version
***
upload_node_lambda_function.sh builds and uploads AWS lambda function written by Node.js.
Usage: upload_node_lambda_function.sh <SOURCE_DIRECTORY> <FUNCTION_NAME>
Options:
--help Print this
--version Show version
***
stopEc2Instance.js is node script which stops EC2 instance of a desired tag name.
You can refresh EC2 instances by following steps.
-
Configure constants
const INSTANCE_TAG_NAME = '__YOUR_INSTANCE_TAG_NAME__'; // Set instance's tag name which you want to stop const AWS_REGION = 'ap-northeast-1'; // Set your aws region const INSTANCE_MIN_COUNT = 0; // Do not stop instance if count of instances of the desired tag name becomes below this value
-
Set to run stopEc2Instance.js on AWS Lambda
-
Set instance's auto scaling more than 1
I found it may cause problems to keep EC2 instance running for a long time because of disk space shortage. It is good manner to refresh EC2 instance periodically for stable server operation.
***
cloudfront_signed_cookie contains scripts to use CloudFront's signed cookie.
- Create CloudFront key pair. For detail, see http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-trusted-signers.html#private-content-creating-cloudfront-key-pairs
- Copy CloudFront private key you got in the previous step as ./private_pk.pem
- Edit signature/policy.json to set domain name, expiration time, etc.
- Get base64 encoded policy and signature by running signature/get_policy.sh and signature/get_signature.sh
- Set generated policy and signature in addition to CloudFront key pair ID you got in the first step to viewer's web browsers. The html in web_example demonstorates how you can do that.
I wrote an article for detail.
***
mdfile_link_elasticsearch.rb runs Elasticsearch on linked URLs in a markdown format file.
- Run
bunlde install
- Create a markdown file as source.md on which Elasticsearch is run
- Set created file name to MD_FILENAME in mdfile_link_elasticsearch.rb
- Run
ruby mdfile_link_elasticsearch.rb <query>
- ruby
- elasticsearch gem