Fix the call for getting instance data

Do not use name alias, use the IP address for this
This commit is contained in:
Clemens Schwaighofer
2023-12-22 13:31:33 +09:00
parent 694f04313c
commit 8fb833d3c4

View File

@@ -62,11 +62,14 @@ case "${1,,}" in
;;
esac;
# collect info via: curl http://instance-data/latest/meta-data/
instance_id=$(curl -s http://instance-data/latest/meta-data/instance-id)
account_id=$(curl -s http://instance-data/latest/meta-data/identity-credentials/ec2/info/ | jq -r .AccountId)
region=$(curl -s http://instance-data/latest/meta-data/placement/region)
# collect info via: curl http://169.254.169.254/latest/meta-data/
instance_data=$(
TOKEN=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` &&
curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/dynamic/instance-identity/document
)
instance_id=$(echo "${instance_data}" | jq .instanceId)
account_id=$(echo "${instance_data}" | jq .accountId)
region=$(echo "${instance_data}" | jq .region)
if [ "${OUTPUT_TARGET}" = "text" ]; then
LOG="${LOG}/check_ssh_user."$(date +"%F_%H%m%S")".log";