本文整理汇总了Java中com.amazonaws.services.ec2.AmazonEC2Async.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonEC2Async.shutdown方法的具体用法?Java AmazonEC2Async.shutdown怎么用?Java AmazonEC2Async.shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.AmazonEC2Async
的用法示例。
在下文中一共展示了AmazonEC2Async.shutdown方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSnapshotFromTagName
import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
public void createSnapshotFromTagName(TagNameRequest tagNameRequest, Context context) {
LambdaLogger logger = context.getLogger();
logger.log("create ebs snapshot from tag name Start. backup target[" + tagNameRequest + "]");
String regionName = System.getenv("AWS_DEFAULT_REGION");
AmazonEC2Async client = RegionUtils.getRegion(regionName).createClient(AmazonEC2AsyncClient.class,
new DefaultAWSCredentialsProviderChain(), cc);
try {
List<Volume> volumes = describeBackupVolumes(client, tagNameRequest);
for (Volume volume : volumes) {
createSnapshot(volume.getVolumeId(), tagNameRequest.getGenerationCount(), context);
}
} finally {
client.shutdown();
}
}
示例2: getInstanceStateName
import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
public String getInstanceStateName(InstanceRequest instanceRequest, Context context) {
AmazonEC2Async client = createEC2Client();
try {
DescribeInstancesResult result = client
.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceRequest.getInstanceId()));
List<Instance> instances = result.getReservations().get(0).getInstances();
if (instances.size() != 1) {
throw new RuntimeException("instance can not be found.");
}
return instances.get(0).getState().getName();
} finally {
client.shutdown();
}
}
示例3: stopInstance
import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
StopInstancesResult stopInstance(InstanceRequest instanceRequest, Context context) {
AmazonEC2Async client = createEC2Client();
try {
StopInstancesRequest req = new StopInstancesRequest();
req.setInstanceIds(Arrays.asList(instanceRequest.getInstanceId()));
Future<StopInstancesResult> result = client.stopInstancesAsync(req);
while (!result.isDone()) {
Thread.sleep(100);
}
return result.get();
} catch (Exception e) {
throw new RuntimeException("unexpected error has occured in the stop instance request.", e);
} finally {
client.shutdown();
}
}
示例4: startInstance
import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
StartInstancesResult startInstance(InstanceRequest instanceRequest, Context context) {
AmazonEC2Async client = createEC2Client();
try {
StartInstancesRequest req = new StartInstancesRequest();
req.setInstanceIds(Arrays.asList(instanceRequest.getInstanceId()));
Future<StartInstancesResult> result = client.startInstancesAsync(req);
while (!result.isDone()) {
Thread.sleep(100);
}
return result.get();
} catch (Exception e) {
throw new RuntimeException("unexpected error has occured in the start instance request.", e);
} finally {
client.shutdown();
}
}
示例5: createAMI
import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
String createAMI(ImageCreateRequest request, Context context) {
LambdaLogger logger = context.getLogger();
AmazonEC2Async client = createEC2Client();
String imageId = null;
try {
Future<CreateImageResult> result = client
.createImageAsync(new CreateImageRequest(request.getInstanceId(), request.getAmiName())
.withNoReboot(request.isNoReboot()));
while (!result.isDone()) {
Thread.sleep(1000);
}
imageId = result.get().getImageId();
logger.log("AMI Create Request End. instanceId[" + request.getInstanceId() + "] noReboot["
+ request.isNoReboot() + "] imageId[" + imageId + "]");
} catch (Exception e) {
throw new RuntimeException("An unexpected error at the time of AMI creation has occurred", e);
} finally {
client.shutdown();
}
return imageId;
}
示例6: handleRequest
import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
@Override
public void handleRequest(InputStream is, OutputStream os, Context context) {
LambdaLogger logger = context.getLogger();
String regionName = System.getenv("AWS_DEFAULT_REGION");
AmazonEC2Async client = RegionUtils.getRegion(regionName).createClient(AmazonEC2AsyncClient.class,
new DefaultAWSCredentialsProviderChain(), cc);
try {
ObjectMapper om = new ObjectMapper();
DeregisterImageRequest event = om.readValue(is, DeregisterImageRequest.class);
String imageId = event.getDetail().getRequestParameters().getImageId();
logger.log("Deregister AMI parge snapshot Start. ImageId[" + imageId + "]");
List<Snapshot> snapshots = describeSnapshot(client, imageId, context);
if (snapshots.size() == 0) {
logger.log("Target of snapshot there is nothing.");
} else {
snapshots.stream().forEach(s -> pargeSnapshot(client, s.getSnapshotId(), context));
}
logger.log("[SUCCESS][DeregisterImage]has been completed successfully." + imageId);
} catch (Exception e) {
logger.log("[ERROR][DeregisterImage]An unexpected error has occurred. message[" + e.getMessage() + "]");
} finally {
client.shutdown();
}
}
示例7: imageStateCheckAndParge
import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
void imageStateCheckAndParge(Message message, ImageStateCheckAndPargeRequest request, Context context) {
LambdaLogger logger = context.getLogger();
// parse sqs message
ObjectMapper om = new ObjectMapper();
ImageCreateRequest createAMIRequest;
try {
createAMIRequest = om.readValue(message.getBody(), ImageCreateRequest.class);
} catch (IOException e) {
deleteQueueMessage(message, request, context);
throw new RuntimeException("SQS message could not be parsed");
}
// Control multiple activation of Lambda
String instanceId = createAMIRequest.getInstanceId();
boolean isLockAcquisition = new LambdaLock().lock(instanceId, context);
if (!isLockAcquisition) {
logger.log("[ERROR][ImageStateCheckAndParge][" + instanceId + "]You can not acquire a lock.");
return;
}
long sendMessageTime = createAMIRequest.getSendMessageTimeMillis()
+ 1000 * createAMIRequest.getImageCreatedTimeoutSec();
long now = System.currentTimeMillis();
// Status check of the instance has timed out or not
if (sendMessageTime < now) {
deleteQueueMessage(message, request, context);
throw new RuntimeException("Status check of the instance has timed out. " + createAMIRequest);
}
AmazonEC2Async client = createEC2Client();
try {
String imageState = getImageState(client, createAMIRequest, context);
if (ImageState.Available.toString().equals(imageState)) {
createImageTags(client, createAMIRequest, context);
pargeImage(client, createAMIRequest, context);
deleteQueueMessage(message, request, context);
}
logger.log("[SUCCESS][" + createAMIRequest.getInstanceId() + "] "
+ "Creation of AMI, additional tags, generation management has completed successfully. ["
+ createAMIRequest + "]");
} finally {
client.shutdown();
}
}
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:49,代码来源:ImageStateCheckAndPargeFunction.java
示例8: checkInstanceState
import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
public void checkInstanceState(Message message, String stateName,
InstanceCheckStateRequest checkInstanceStateRequest, Context context) {
LambdaLogger logger = context.getLogger();
ObjectMapper om = new ObjectMapper();
InstanceRequest instanceRequest;
try {
instanceRequest = om.readValue(message.getBody(), InstanceRequest.class);
} catch (IOException e) {
deleteQueueMessage(message, checkInstanceStateRequest, context);
throw new RuntimeException("SQS message could not be parsed");
}
long sendMessageTime = instanceRequest.getSendMessageTimeMillis()
+ 1000 * instanceRequest.getInstanceStateCheckTimeoutSec();
long now = System.currentTimeMillis();
// Status check of the instance has timed out or not
if (sendMessageTime < now) {
deleteQueueMessage(message, checkInstanceStateRequest, context);
throw new RuntimeException("Status check of the instance has timed out. " + instanceRequest);
}
AmazonEC2Async client = createEC2Client();
try {
DescribeInstancesResult result = client
.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceRequest.getInstanceId()));
List<Instance> instances = result.getReservations().get(0).getInstances();
if (instances.size() != 1) {
deleteQueueMessage(message, checkInstanceStateRequest, context);
throw new RuntimeException("instance can not be found.");
}
Instance instance = instances.get(0);
if (stateName.equals(instance.getState().getName())) {
deleteQueueMessage(message, checkInstanceStateRequest, context);
logger.log("[SUCCESS][" + instanceRequest.getInstanceId() + "][checkInstanceState][" + stateName
+ "] Status check of the instance is completed successfully. " + instanceRequest + "]");
}
} finally {
client.shutdown();
}
}
示例9: copySnapshotFromVolumeId
import com.amazonaws.services.ec2.AmazonEC2Async; //导入方法依赖的package包/类
/**
* Find the snapshot the volumeId the key, to get a copy of the latest
* Snapshot
*
* @param volumeIdRequest
* VolumeIdRequest
* @param context
* Context
*/
public void copySnapshotFromVolumeId(VolumeIdRequest volumeIdRequest, Context context) {
LambdaLogger logger = context.getLogger();
String regionName = System.getenv("AWS_DEFAULT_REGION");
AmazonEC2Async client = RegionUtils.getRegion(regionName).createClient(AmazonEC2AsyncClient.class,
new DefaultAWSCredentialsProviderChain(), cc);
try {
String volumeId = volumeIdRequest.getVolumeId();
boolean isLockAcquisition = new LambdaLock().lock(volumeId, context);
if (!isLockAcquisition) {
logger.log("[ERROR][EBSCopySnapshot][" + volumeId + "]You can not acquire a lock.");
return;
}
List<Filter> filters = new ArrayList<>();
filters.add(new Filter().withName("volume-id").withValues(volumeId));
filters.add(new Filter().withName("tag:VolumeId").withValues(volumeId));
filters.add(new Filter().withName("tag:BackupType").withValues("snapshot"));
DescribeSnapshotsRequest snapshotRequest = new DescribeSnapshotsRequest().withFilters(filters);
DescribeSnapshotsResult snapshotResult = client.describeSnapshots(snapshotRequest);
// sort and get latest snapshot
List<Snapshot> snapshots = snapshotResult.getSnapshots();
Collections.sort(snapshots, new SnapshotComparator());
int snapshotsSize = snapshots.size();
if (snapshotsSize == 0) {
throw new RuntimeException("The copy source snapshot can not be found");
}
Snapshot snapshot = snapshots.get(snapshots.size() - 1);
String sourceSnapshotId = snapshot.getSnapshotId();
copySnapshot(sourceSnapshotId, volumeIdRequest.getDestinationRegion(), volumeIdRequest.getGenerationCount(),
context);
} catch (Exception e) {
logger.log("[ERROR][EBSCopySnapshot][" + volumeIdRequest.getVolumeId() + "] message[" + e.getMessage()
+ "] stackTrace[" + getStackTrace(e) + "]");
} finally {
client.shutdown();
}
}