User guide

blockList.add(blockDeviceMapping);
// Set the block device mapping configuration in the launch specifications.
50 launchSpecification.setBlockDeviceMappings(blockList);
// Add the launch specification.
requestRequest.setLaunchSpecification(launchSpecification);
55 // Call the RequestSpotInstance API.
RequestSpotInstancesResult requestResult = ec2.requestSpotInstances(re
questRequest);
Assuming you wanted to re-attach this volume to your instance on startup, you can also use the block
device mapping settings. Alternatively, if you attached a non-root partition, you can specify the Amazon
EBS volumes you want to attach to your Spot instance after it resumes.You do this simply by specifying
a snapshot ID in your EbsBlockDevice and alternative device name in your BlockDeviceMapping
objects. By leveraging block device mappings, it can be easier to bootstrap your instance.
Using the root partition to checkpoint your critical data is a great way to manage the potential for interruption
of your instances. For more methods on managing the potential of interruption, please visit the Managing
Interruption video.
How to Tag Your Spot Requests and Instances
Adding tags to EC2 resources can simplify the administration of your cloud infrastructure. A form of
metadata, tags can be used to create user-friendly names, enhance searchability, and improve coordination
between multiple users.You can also use tags to automate scripts and portions of your processes.
To add tags to your resources, you need to tag them after they have been requested. Specifically, you
must add a tag after a Spot request has been submitted or after the RunInstances call has been
performed. The following code example illustrates adding tags.
1
/*
* Copyright 2010-2011 Amazon.com, Inc. or its affiliates. All Rights Re
served.
*
5 * Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
10 *
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
15 */
package com.amazonaws.codesamples.advanced;
import java.io.IOException;
import java.util.ArrayList;
20 import java.util.List;
import com.amazonaws.AmazonServiceException;
Version v1.0.0
56
AWS SDK for Java Developer Guide
Tutorial: Advanced Amazon EC2 Spot Request
Management