<commit_before>#!/bin/bash
# This script print a list of IPs of the EC2 instances in your current ECS
# cluster.
set -eu

# Read agent configuration
if [ -e /etc/ecs/ecs.config ]; then
  . /etc/ecs/ecs.config
else
  ECS_CLUSTER=default
fi

aws=/usr/local/bin/aws

export AWS_DEFAULT_REGION=$(curl -s curl http://169.254.169.254/latest/dynamic/instance-identity/document | \
                            jq -r .region)
current_instance_id=$(curl -s curl http://169.254.169.254/latest/dynamic/instance-identity/document | \
                      jq -r .instanceId)

ecs_container_instances=$($aws ecs list-container-instances --cluster $ECS_CLUSTER | \
	jq -r '.containerInstanceArns | join(" ")')

if [ -z "$ecs_container_instances" ]; then
# no peers found
  exit 0
fi

ec2_instances=$($aws ecs describe-container-instances --cluster $ECS_CLUSTER --container-instances $ecs_container_instances | \
	jq -r '.containerInstances | .[] | .ec2InstanceId')

# Filter out current instance
filtered_instances=""
for instance_id in $ec2_instances; do
  if [ "$instance_id" != "$current_instance_id" ]; then
    filtered_instances="$filtered_instances $instance_id"
  fi
done

if [ -z "$filtered_instances" ]; then
# no peers found
  exit 0
fi

ec2_ips=$($aws ec2 describe-instances --instance-ids $filtered_instances | \
	jq -r '.Reservations | .[] | .Instances | .[] | .NetworkInterfaces | .[] | .PrivateIpAddress')

echo $ec2_ips | tr '\n' ' '
echo
<commit_msg>[aws-ecs] Obtain peers using the current autoscaling group<commit_after>#!/bin/bash
# This script print a list of IPs of the EC2 instances in your current ECS
# cluster.
set -eu

aws=/usr/local/bin/aws

export AWS_DEFAULT_REGION=$(curl -s curl http://169.254.169.254/latest/dynamic/instance-identity/document | \
                            jq -r .region)
current_instance_id=$(curl -s curl http://169.254.169.254/latest/meta-data/instance-id)
current_autoscaling_group=$(aws autoscaling describe-auto-scaling-instances | \
                            jq -r ".AutoScalingInstances[] | select(.InstanceId == \"$current_instance_id\") | .AutoScalingGroupName")

if [ -z "$current_autoscaling_group" ]; then
  # Instance doesn't belong to an autoscaling group
  exit 1
fi

peer_instances=$($aws autoscaling describe-auto-scaling-instances | \
                jq -r ".AutoScalingInstances[] | select(.AutoScalingGroupName == \"$current_autoscaling_group\" and .InstanceId != \"$current_instance_id\") | .InstanceId")

if [ -z "$peer_instances" ]; then
# no peers found
  exit 0
fi

peer_ips=$($aws ec2 describe-instances --instance-ids $peer_instances | \
	jq -r '.Reservations | .[] | .Instances | .[] | .NetworkInterfaces | .[] | .PrivateIpAddress')

echo $peer_ips | tr '\n' ' '
echo

{'fraction_non_alphanumeric': 0.13706140350877194, 'fraction_numerical': 0.0222953216374269, 'mean_word_length': 3.428802588996764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7611453', 'n_tokens_mistral': 970, 'n_tokens_neox': 899, 'n_words': 220}