本文整理汇总了Java中com.amazonaws.services.ec2.AmazonEC2Async类的典型用法代码示例。如果您正苦于以下问题:Java AmazonEC2Async类的具体用法?Java AmazonEC2Async怎么用?Java AmazonEC2Async使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmazonEC2Async类属于com.amazonaws.services.ec2包,在下文中一共展示了AmazonEC2Async类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import com.amazonaws.services.ec2.AmazonEC2Async; //导入依赖的package包/类
@Override
public void process(AmazonEC2Async amazonEC2Async, Instance instance) {
amazonEC2Async.stopInstancesAsync(
new StopInstancesRequest().withInstanceIds(instance.getInstanceId()),
new AsyncHandler<StopInstancesRequest, StopInstancesResult>() {
@Override
public void onError(Exception exception) {
log.warn("something went wrong stopping the server {}",
exception.getLocalizedMessage());
}
@Override
public void onSuccess(StopInstancesRequest request, StopInstancesResult result) {
onSuccessStop(instance);
}
});
}
示例2: amazonEC2Async
import com.amazonaws.services.ec2.AmazonEC2Async; //导入依赖的package包/类
@Override
public AmazonEC2Async amazonEC2Async() {
User user = authenticationService.getCurrentUser();
String accessKey = user.getAwsKey();
String secretKey = user.getAwsSecret();
String region = user.getAwsRegion();
if (secretKey.equals("") || accessKey.equals("") || region.equals("")) {
return null;
}
BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(
accessKey, secretKey);
return AmazonEC2AsyncClientBuilder.standard().withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials))
.build();
}
示例3: 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();
}
}
示例4: getSnapshotIdsFromImageId
import com.amazonaws.services.ec2.AmazonEC2Async; //导入依赖的package包/类
List<String> getSnapshotIdsFromImageId(AmazonEC2Async client, ImageCreateRequest request, Context context) {
// LambdaLogger logger = context.getLogger();
String imageId = request.getImageId();
DescribeImagesResult result = client.describeImages(new DescribeImagesRequest().withImageIds(imageId));
List<String> snapshotIds = new ArrayList<String>();
for (Image image : result.getImages()) {
for (BlockDeviceMapping block : image.getBlockDeviceMappings()) {
snapshotIds.add(block.getEbs().getSnapshotId());
}
}
return snapshotIds;
}
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:17,代码来源:ImageStateCheckAndPargeFunction.java
示例5: 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();
}
}
示例6: 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();
}
}
示例7: 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();
}
}
示例8: attachSnapshotTags
import com.amazonaws.services.ec2.AmazonEC2Async; //导入依赖的package包/类
void attachSnapshotTags(AmazonEC2Async client, String sourceSnapshotId, String snapshotId) {
DescribeSnapshotsResult result = client
.describeSnapshots(new DescribeSnapshotsRequest().withSnapshotIds(sourceSnapshotId));
List<Snapshot> snapshots = result.getSnapshots();
if (snapshots.size() != 1) {
throw new RuntimeException("snapshot can not found. sourceSnapshotId[" + snapshotId + "]");
}
List<Tag> sourceSnapshotTags = snapshots.get(0).getTags();
List<Tag> tags = new ArrayList<Tag>();
tags.addAll(sourceSnapshotTags);
tags.add(new Tag("SourceSnapshotId", sourceSnapshotId));
tags.add(new Tag("BackupType", "copy-snapshot")); // overwrite
CreateTagsRequest snapshotTagsRequest = new CreateTagsRequest().withResources(snapshotId);
snapshotTagsRequest.setTags(tags);
client.createTags(snapshotTagsRequest);
}
示例9: syncAll
import com.amazonaws.services.ec2.AmazonEC2Async; //导入依赖的package包/类
@Override
public Iterable<Instance> syncAll(AmazonEC2Async amazonEC2Async) {
DescribeInstancesRequest request = new DescribeInstancesRequest();
DescribeInstancesResult response = amazonEC2Async.describeInstances(request);
return processResponse(response);
}
示例10: run
import com.amazonaws.services.ec2.AmazonEC2Async; //导入依赖的package包/类
@Override
public void run() {
for (User user : authenticationService.getLocalUsers()) {
AmazonEC2Async amazonEC2Async = ec2UserClient.amazonEC2Async(user);
if (amazonEC2Async != null) {
Iterable<Instance> instances = ec2Sync.syncAll(amazonEC2Async);
for (Instance instance : instances) {
notificationService.send("server_refresh", "server_refresh", jsonTransformService.write(instance));
}
}
}
}
示例11: run
import com.amazonaws.services.ec2.AmazonEC2Async; //导入依赖的package包/类
@Override
public void run() {
Iterable<Instance> instances = instanceRepository.findAllByStateAndSwordfishIsTrueAndProductionIsFalse("running");
for (Instance instance : instances) {
User user = authenticationService.getLocalUserById(instance.getUserId());
AmazonEC2Async amazonEC2Async = ec2UserClient.amazonEC2Async(user);
ec2Stop.process(amazonEC2Async, instance);
}
}
示例12: describeBackupVolumes
import com.amazonaws.services.ec2.AmazonEC2Async; //导入依赖的package包/类
List<Volume> describeBackupVolumes(AmazonEC2Async client, TagNameRequest target) {
Filter tagKey = new Filter().withName("tag-key").withValues("Backup");
Filter tagValue = new Filter().withName("tag-value").withValues(target.getTagName());
DescribeVolumesRequest req = new DescribeVolumesRequest().withFilters(tagKey, tagValue);
DescribeVolumesResult result = client.describeVolumes(req);
return result.getVolumes();
}
示例13: attachSnapshotTags
import com.amazonaws.services.ec2.AmazonEC2Async; //导入依赖的package包/类
void attachSnapshotTags(AmazonEC2Async client, String volumeId, String snapshotId) {
List<Tag> tags = new ArrayList<Tag>();
tags.add(new Tag("VolumeId", volumeId));
tags.add(new Tag("BackupType", "snapshot"));
CreateTagsRequest snapshotTagsRequest = new CreateTagsRequest().withResources(snapshotId);
snapshotTagsRequest.setTags(tags);
client.createTags(snapshotTagsRequest);
}
示例14: pargeEbsSnapshot
import com.amazonaws.services.ec2.AmazonEC2Async; //导入依赖的package包/类
void pargeEbsSnapshot(AmazonEC2Async client, String volumeId, int generationCount, Context context) {
LambdaLogger logger = context.getLogger();
logger.log("Parge snapshot start. VolumeId[" + volumeId + "] generationCount[" + generationCount + "]");
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);
List<Snapshot> snapshots = snapshotResult.getSnapshots();
Collections.sort(snapshots, new SnapshotComparator());
int snapshotSize = snapshots.size();
if (generationCount < snapshotSize) {
for (int i = 0; i < snapshotSize - generationCount; i++) {
Snapshot snapshot = snapshots.get(i);
if (SnapshotState.Completed.toString().equals(snapshot.getState())) {
String snapshotId = snapshot.getSnapshotId();
pargeSnapshot(client, snapshotId);
logger.log("Parge EBS snapshot. snapshotId[" + snapshotId + "] volumeId[" + volumeId + "]");
}
}
}
}
示例15: 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;
}