cloudformation-coverage-roadmap icon indicating copy to clipboard operation
cloudformation-coverage-roadmap copied to clipboard

AWS::EC2::SpotFleet Tag root Volume or attach Volume

Open joaquinpretell-belcorp opened this issue 3 years ago • 0 comments

Name of the resource

AWS::EC2::SpotFleet

Resource name

No response

Description

Hello,

I'm using cloudformation to deploy EC2 instances via SpotFleet and i want to know if there is a way to tag my ec2 volumes. From my search i found AWS::EC2::Instance have this parameter "PropagateTagsToVolumeOnCreation", but AWS::EC2::SpotFleet doesnt have it. I want to know if that parameter will work on spotfleet too or theres another way to do it.

I also found this page, but i dont know if this will work with spotfleet too. https://aws.amazon.com/es/premiumsupport/knowledge-center/cloudformation-instance-tag-root-volume/ I use the spotfleet on a ECS cluster so from what i see in this code i have to add the tag information in this part of my code:

          "UserData": {
            "Fn::Base64": {
              "Fn::Join": [
                "",
                [
                  "#!/bin/bash\n",
                  "echo ECS_CLUSTER=",
                  {
                    "Ref": "ECSCluster"
                  },
                  " >> /etc/ecs/ecs.config\n",
                  "export PATH=/usr/local/bin:$PATH\n",
                  "yum -y install jq\n",
                  "easy_install pip\n",
                  "pip install awscli\n",
                  "aws configure set default.region ",
                  {
                    "Ref": "AWS::Region"
                  },
                  "\n",
                  "cat <<EOF > /etc/init/spot-instance-termination-notice-handler.conf\n",
                  "description 'Start spot instance termination handler monitoring script'\n",
                  "author 'Amazon Web Services'\n",
                  "start on started ecs\n",
                  "script\n",
                  "echo $$ > /var/run/spot-instance-termination-notice-handler.pid\n",
                  "exec /usr/local/bin/spot-instance-termination-notice-handler.sh\n",
                  "end script\n",
                  "pre-start script\n",
                  "logger \"[spot-instance-termination-notice-handler.sh]: spot instance termination\n",
                  "notice handler started\"\n",
                  "end script\n",
                  "EOF\n",
                  "cat <<EOF > /usr/local/bin/spot-instance-termination-notice-handler.sh\n",
                  "#!/bin/bash\n",
                  "while sleep 5; do\n",
                  "if [ -z $(curl -Isf http://169.254.169.254/latest/meta-data/spot/termination-time)]; then\n",
                  "/bin/false\n",
                  "else\n",
                  "logger \"[spot-instance-termination-notice-handler.sh]: spot instance termination notice detected\"\n",
                  "STATUS=DRAINING\n",
                  "ECS_CLUSTER=$(curl -s http://localhost:51678/v1/metadata | jq .Cluster | tr -d \")\n",
                  "CONTAINER_INSTANCE=$(curl -s http://localhost:51678/v1/metadata | jq .ContainerInstanceArn | tr -d \")\n",
                  "logger \"[spot-instance-termination-notice-handler.sh]: putting instance in state $STATUS\"\"\n",
                  "/usr/local/bin/aws ecs update-container-instances-state --cluster $ECS_CLUSTER --container-instances $CONTAINER_INSTANCE --status $STATUS\n",
                  "logger \"[spot-instance-termination-notice-handler.sh]: putting myself to sleep...\"\n",
                  "sleep 120 # exit loop as instance expires in 120 secs after terminating notification\n",
                  "fi\n",
                  "done\n",
                  "EOF\n",
                  "chmod +x /usr/local/bin/spot-instance-termination-notice-handler.sh"
                ]
              ]
            }
          }
        },
        {
          "TagSpecifications": [
            {
              "ResourceType": "instance",
              "Tags" : [
                {"Key": "Name", "Value": "Green"}
              ]
            }
          ],

I wonder how i would use the code in mine, because i dont get it at all.

Greetings.

Other Details

No response

joaquinpretell-belcorp avatar Jun 30 '22 17:06 joaquinpretell-belcorp