-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathaws-ssm-ssh-proxy-command_start-ec2-instance.sh
More file actions
executable file
·40 lines (35 loc) · 1.26 KB
/
aws-ssm-ssh-proxy-command_start-ec2-instance.sh
File metadata and controls
executable file
·40 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env sh
set -eu
instance_id="$1"
REGION_SEPARATOR='--'
if echo "$instance_id" | grep -q -e "${REGION_SEPARATOR}"
then
export AWS_REGION="${instance_id##*"$REGION_SEPARATOR"}"
instance_id="${instance_id%%"$REGION_SEPARATOR"*}"
fi
START_INSTANCE_TIMEOUT=300
START_INSTANCE_CHECK_INTERVAL=5
STATUS=$(aws ssm describe-instance-information --filters Key=InstanceIds,Values="$instance_id" --output text --query 'InstanceInformationList[0].PingStatus')
if [ "$STATUS" != 'Online' ]
then
aws ec2 start-instances --instance-ids "${instance_id}" --profile "${AWS_PROFILE}" --region "${AWS_REGION}"
>/dev/stderr echo "Waiting for EC2 Instance ${instance_id}..."
START_INSTANCE_START="$(date +%s)"
while [ $(( $(date +%s) - "$START_INSTANCE_START")) -le ${START_INSTANCE_TIMEOUT} ]
do
>/dev/stderr printf "."
sleep ${START_INSTANCE_CHECK_INTERVAL}
STATUS=$(aws ssm describe-instance-information --filters Key=InstanceIds,Values="$instance_id" --output text --query 'InstanceInformationList[0].PingStatus')
if [ "$STATUS" = 'Online' ]
then
break
fi
done
>/dev/stderr echo
if [ "$STATUS" != 'Online' ]
then
>/dev/stderr echo "Timeout."
exit 1
fi
fi
exec "$PWD/${0%/*}/aws-ssm-ssh-proxy-command.sh" "$@"