user data bash script fails with Provided region_name doesn't match a support format.
when running the script from comand line works fine.
#!/bin/bash
Hostname=”`wget -qO- http://instance-data/latest/meta-data/hostname`”
InstanceId=”`wget -qO- http://instance-data/latest/meta-data/instance-id`”
Region=”`wget -qO- http://instance-data/latest/meta-data/placement/region`”
echo $Region
aws ec2 create-tags --resources $InstanceId --tags Key=Hostname,Value=$Hostname --region $Region
Fixed the issue aws was changing the double quote to left and right double quote. I recoded it.
#! /bin/bash
Hostname=$(wget -qO- http://instance-data/latest/meta-data/hostname)
InstanceId=$(wget -qO- http://instance-data/latest/meta-data/instance-id)
Region=$(wget -qO- http://instance-data/latest/meta-data/placement/region)
aws ec2 create-tags --resources $InstanceId --tags Key=Hostname,Value=$Hostname --
region $Region