0

According to this link it is possible to tag spot fleet instances. Tags are automatically propagated to the launched instances. Is it possible to do the same for normal spot instances? My approach so far

ec2 = Aws::EC2::Resource.new({region: region, credentials: creds})
launch_specification ={
  :security_groups => ['ccc'],
  :ebs_optimized => true,
  :image_id => "image_id",
  :instance_type => "type",
  :key_name => "key",
  :placement => {:group_name => "ggg"},
  :user_data => ""        
} 
resp = ec2.client.request_spot_instances(:instance_count => count,
  :launch_specification => launch_specification,
  :spot_price => price.to_s,
  :type => 'one-time',
  :dry_run => false
)
resp.spot_instance_requests.each do |sir|
  ec2.create_tags({
    dry_run: false,
    resources: [sir.spot_instance_request_id],
    tags: [
          {
            key: "owner",
            value: "ooo",
          },
        ],
      })
end

Tags are created for for the spot_instance_request, but are not propagated to the launched instances.

Rojj
  • 1,170
  • 1
  • 12
  • 32
  • Maybe you're looking for [`request_spot_fleet()`](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/EC2/Client.html#request_spot_fleet-instance_method)? – Michael - sqlbot May 22 '18 at 09:03
  • No. `request_spot_fleet` is based on overall spot instances capacity (fleet). I want to launch specific spot instances. – Rojj May 22 '18 at 09:08
  • 2
    Spot fleet requests are a superset of spot instance requests. You can request a target capacity of 1. Otherwise, [*"you can assign a tag to a Spot Instance request after you create it. The tags that you create for your Spot Instance requests only apply to the requests. These tags are not added automatically to the Spot Instance that the Spot service launches to fulfill the request. You must add tags to a Spot Instance yourself after the Spot Instance is launched."*](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-requests.html#concepts-spot-instances-request-tags) – Michael - sqlbot May 22 '18 at 09:21

0 Answers0