Skip to content

Instantly share code, notes, and snippets.

@mlf4aiur
mlf4aiur / get_ecs_service_instance_ips.sh
Last active December 2, 2016 09:43
Get AWS ECS service instance IPs
function get_ecs_service_instance_ips () {
local cluster_name=$1
local service_name=$2
local tasks
local container_arns
local ec2_instance_ids
# Get tasks
tasks=$(aws --output json \
ecs list-tasks \
@mlf4aiur
mlf4aiur / get_ecs_cluster_instance_ips.sh
Last active July 12, 2018 23:14
Get AWS ECS cluster instance IPs
function get_ecs_cluster_instance_ips () {
local cluster_name=$1
local container_arns
local ec2_instance_ids
# Get container instances
container_arns=$(aws --output json \
ecs list-container-instances \
--cluster "${cluster_name}" | \
jq '.containerInstanceArns[]' | tr -d '"' | tr "\n" " ")
function update_ecs_agent () {
local cluster_name=$1
local container_arns
local container_arn
# Get container instances
container_arns=$(aws --output json \
ecs list-container-instances \
--cluster "${cluster_name}" | \
jq '.containerInstanceArns[]' | tr -d '"' | tr "\n" " ")
for container_arn in ${container_arns}; do
@mlf4aiur
mlf4aiur / cleanup_ecr_untagged_images.sh
Last active November 18, 2016 02:13
Cleanup AWS ECR untagged images
#!/bin/bash
function delete_image () {
local repo_name=$1
local image_digest=$2
echo "${image_digest}"
aws --out=json \
ecr \
batch-delete-image \
--repository-name="${repo_name}" \
function get_ecs_service_instances () {
local cluster_name=$1
local service_name=$2
local tasks
local container_arns
local ec2_instance_ids
echo "Cluster: ${cluster_name}"
echo "Service: ${service_name}"
echo "EC2 instances:"
function stop_ecs_service_tasks () {
local cluster_name=$1
local service_name=$2
local wait_time=${3:-10}
local tasks
local task
# Get tasks
tasks=$(aws --output json \
ecs list-tasks \