use of com.amazonaws.services.s3.model.Filter in project aws-doc-sdk-examples by awsdocs.
the class FindRunningInstances method findRunningEC2Instances.
// snippet-start:[ec2.java2.running_instances.main]
public static void findRunningEC2Instances(Ec2Client ec2) {
try {
String nextToken = null;
do {
Filter filter = Filter.builder().name("instance-state-name").values("running").build();
DescribeInstancesRequest request = DescribeInstancesRequest.builder().filters(filter).build();
DescribeInstancesResponse response = ec2.describeInstances(request);
for (Reservation reservation : response.reservations()) {
for (Instance instance : reservation.instances()) {
System.out.printf("Found Reservation with id %s, " + "AMI %s, " + "type %s, " + "state %s " + "and monitoring state %s", instance.instanceId(), instance.imageId(), instance.instanceType(), instance.state().name(), instance.monitoring().state());
System.out.println("");
}
}
nextToken = response.nextToken();
} while (nextToken != null);
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of com.amazonaws.services.s3.model.Filter in project aws-doc-sdk-examples by awsdocs.
the class FindRunningInstances method main.
public static void main(String[] args) {
// snippet-start:[ec2.java1.running_instances.main]
AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
try {
// Create the Filter to use to find running instances
Filter filter = new Filter("instance-state-name");
filter.withValues("running");
// Create a DescribeInstancesRequest
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.withFilters(filter);
// Find the running instances
DescribeInstancesResult response = ec2.describeInstances(request);
for (Reservation reservation : response.getReservations()) {
for (Instance instance : reservation.getInstances()) {
// Print out the results
System.out.printf("Found reservation with id %s, " + "AMI %s, " + "type %s, " + "state %s " + "and monitoring state %s", instance.getInstanceId(), instance.getImageId(), instance.getInstanceType(), instance.getState().getName(), instance.getMonitoring().getState());
}
}
System.out.print("Done");
} catch (SdkClientException e) {
e.getStackTrace();
}
// snippet-end:[ec2.java1.running_instances.main]
}
use of com.amazonaws.services.s3.model.Filter in project aws-doc-sdk-examples by awsdocs.
the class S3Encrypt method strictAuthenticatedEncryption_RangeGet_CustomerManagedKey.
// snippet-end:[s3.java1.s3_encrypt.strict_authenticated_encryption]
/**
* Strict authenticated encryption mode does not support ranged GETs. This is because we must use AES/CTR for ranged
* GETs which is not an authenticated encryption algorithm. To do a partial get using authenticated encryption you have to
* get the whole object and filter to the data you want.
*/
public void strictAuthenticatedEncryption_RangeGet_CustomerManagedKey() throws NoSuchAlgorithmException {
SecretKey secretKey = KeyGenerator.getInstance("AES").generateKey();
AmazonS3Encryption s3Encryption = AmazonS3EncryptionClientBuilder.standard().withRegion(Regions.US_WEST_2).withCryptoConfiguration(new CryptoConfiguration(CryptoMode.StrictAuthenticatedEncryption)).withEncryptionMaterials(new StaticEncryptionMaterialsProvider(new EncryptionMaterials(secretKey))).build();
s3Encryption.putObject(BUCKET_NAME, ENCRYPTED_KEY, "some contents");
try {
s3Encryption.getObject(new GetObjectRequest(BUCKET_NAME, ENCRYPTED_KEY).withRange(0, 2));
} catch (SecurityException e) {
System.err.println("Range GET is not supported with authenticated encryption");
}
}
use of com.amazonaws.services.s3.model.Filter in project checker-framework by typetools.
the class WithOwnersFilter method correct3.
public static void correct3(AmazonEC2 client) {
DescribeImagesRequest request = new DescribeImagesRequest();
request.withFilters(new Filter("name").withValues(IMG_NAME), new Filter("owner").withValues("my_aws_acct"));
client.describeImages(request);
}
use of com.amazonaws.services.s3.model.Filter in project checker-framework by typetools.
the class WithOwnersFilter method correct2.
public static void correct2(AmazonEC2 client) {
DescribeImagesRequest request = new DescribeImagesRequest();
request.withFilters(new Filter("name").withValues(IMG_NAME));
request.withFilters(new Filter("owner").withValues("my_aws_acct"));
client.describeImages(request);
}
Aggregations