Wednesday, September 5, 2018

AWS Code examples - 1

1)  Write  a program  to create a snapshot  and return the snapshot id.

public static String  createSnapshot(VerificationHost host, AmazonEC2Client client, String volumeId) {

CreateSnapshotRequest req = new CreateSnapshotRequest().withVolumeId(volumeId);

CreateSnapshotResult res = client.createSnapshot(req);
String snapshotId = res.getSnapshot().getSnapshotId();

Filter filter = new Filter().withName(SNAPSHOT_ID_ATTRIBUTE).withValues(snapshotId);

DescribeSnapshotRequest snapshotRequest = new DescribeSnapshotRequest().withSnapshotIds(snapshotId).withFilters(filter);

host.waitFor("Timeout waiting for creating snapshot".() -> {
   DescribeSnapshotsResult snapshotsResult  = client.describeSnapshots(snapshotsRequest);
  String state = snapshotsResult.getSnapshots().get(0).getState();

 if(state.equalsIgnoreCase(SNAPSHOT_STATUS_COMPLETE) {
  return true;
}
return false;
});
return snapshotId;

}


No comments:

Post a Comment

Hyderabad Trip - Best Places to visit

 Best Places to Visit  in Hyderabad 1.        1. Golconda Fort Maps Link :   https://www.google.com/maps/dir/Aparna+Serene+Park,+Masj...