Is there a way to tag a root volume when initializing from the cloudformation template?

前端 未结 4 1581
傲寒
傲寒 2021-02-13 01:15

I am creating an instance through the cloud formation script.

The only way I found to attach an OS partition was through \"BlockDeviceMappings\" property. (I\'ve tried t

4条回答
  •  北海茫月
    2021-02-13 02:06

    This is what I did in my ec2 userdata. I think it's much simpler than above answer.

    Key=
    Value=
    Region=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | grep -oP "(?<=\"region\" : \")[^\"]+")
    
    aws ec2 create-tags --resources $(aws ec2 describe-instances --instance-ids $(curl -s http://169.254.169.254/latest/meta-data/instance-id) --region $Region | grep -oP "(?<=\"VolumeId\": \")[^\"]+") --tags Key=$Key,Value=$Value --region $Region
    

提交回复
热议问题