File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,22 @@ function aws_wrapper_get_ips_in_asg {
169
169
echo " $instances " | jq -r " .Reservations[].Instances[].$ip_param "
170
170
}
171
171
172
+ # Return a space-separated list of IPs belonging to instances with specific tag values.
173
+ # If use_public_ips is "true", these will be the public IPs; otherwise, these will be the private IPs.
174
+ function aws_wrapper_get_ips_with_tag {
175
+ local readonly tag_key=" $1 "
176
+ local readonly tag_value=" $2 "
177
+ local readonly aws_region=" $3 "
178
+ local readonly use_public_ips=" $4 "
179
+
180
+ local instances
181
+ instances=$( aws_get_instances_with_tag " $tag_key " " $tag_value " " $aws_region " )
182
+ assert_not_empty_or_null " $instances " " Get info about Instances with tag $tag_key set to $tag_value "
183
+
184
+ local readonly ip_param=$( [[ " $use_public_ips " == " true" ]] && echo " PublicIpAddress" || echo " PrivateIpAddress" )
185
+ echo " $instances " | jq -r " .Reservations[].Instances[].$ip_param "
186
+ }
187
+
172
188
# Return a space-separated list of hostnames in the given ASG. If use_public_hostnames is "true", these will be the
173
189
# public hostnames; otherwise, these will be the private hostnames.
174
190
function aws_wrapper_get_hostnames_in_asg {
Original file line number Diff line number Diff line change @@ -62,6 +62,17 @@ function aws_get_instance_tags {
62
62
--filters " Name=resource-type,Values=instance" " Name=resource-id,Values=$instance_id "
63
63
}
64
64
65
+ # Get the instances with a given tag and in a specific region. Returns JSON from the AWS CLI's describe-instances command.
66
+ function aws_get_instances_with_tag {
67
+ local readonly tag_key=" $1 "
68
+ local readonly tag_value=" $2 "
69
+ local readonly instance_region=" $3 "
70
+
71
+ aws ec2 describe-instances \
72
+ --region " $instance_region " \
73
+ --filters " Name=tag:$tag_key ,Values=$tag_value "
74
+ }
75
+
65
76
# Describe the given ASG in the given region. Returns JSON from the AWS CLI's describe-auto-scaling-groups command.
66
77
function aws_describe_asg {
67
78
local readonly asg_name=" $1 "
You can’t perform that action at this time.
0 commit comments