Delete ec2 volume via aws java sdk? - java

I wanted to delete AWS EC2 volumes which were attached to instances.
But, I could not find any implementation in AWS's java sdk to do so.
Its equivalent cli command is :
/usr/bin/aws ec2 delete-volume --volume-id $volumeId
But I want to do it via java sdk.
Any suggestions?

Use deleteVolume(DeleteVolumeRequest request):
Deletes the specified EBS volume. The volume must be in the available state (not attached to an instance).
See also: DeleteVolume documentation

Related

Check if secure transfer is enabled in azure storage account

We can set if secure tansfer is enabled or not when creating storage account in azure portal but is there a way to check if a storage account is enabled or not through api/sdk?
Yes, it is possible to do so. If you're using Storage Resource Provider's Get Properties operation on a storage account, you will see a property called supportsHttpsTrafficOnly. True value indicates that secure transfer is enabled and false value indicates it otherwise.
I have not used Java SDK but a quick look at StorageAccount class indicates that this capability is exposed through enableHttpsTrafficOnly() property. So it should be possible to get this information through SDK as well.
You can get this information in multiple ways depending on your preference:
Azure CLI
Azure PowerShell
.Net Fluent SDK
Java SDK
and other SDKs that exist
Here are the snippets reduced to only display the value of the field.
Replace the placeholders <..> with their real values. The storage account will be identified by resource group name and storage account name.
The solutions presume that you now how to authenticate.
Azure CLI
az storage account show --resource-group <ResourceGroupName> --name <StorageAccountName> --query enableHttpsTrafficOnly
Azure PowerShell
Get-AzStorageAccount -ResourceGroupName <ResourceGroupName> -Name <StorageAccountName> | Select-Object EnableHttpsTrafficOnly
Fluent SDK (C# console app)
//requires references for Microsoft.Azure.Management.Fluent and Microsoft.Azure.Management.Storage.Fluent
IAzure myAzure = Azure.Authenticate("azure.auth").WithDefaultSubscription();
Console.WriteLine(myAzure.StorageAccounts.GetByResourceGroup("<ResourceGroupName>", "<StorageAccountName>").Inner.EnableHttpsTrafficOnly);
Java SDK
There is also an SDK for Java and it seems to work in an identical fashion. Looking at the code, you should be able to achieve the same, as with the .NET SDK.
Here is a link for storage account management samples with Java and the SDK:
Java SDK Storage Account Management Go to the section List storage accounts and adapt the sample similar to my C# code (apply getByResourceGroup(...) and .Inner.enableHttpsTrafficOnly
I hope this is of some help.

'Google App Engine does not support the use of proxies' error when connecting to Google Compute Engine proxy server

We have a Java 7 Google App Engine instance which we are trying to connect to an external API. Because the API server requires whitelisted IP addresses for access, we have set up a Google Compute Engine proxy server with Squid installed (a solution proposed elsewhere) and then whitelisted the external IP address of the proxy server on the API server.
This way, requests made from GAE will be redirected to GCE first, allowing API calls to be made. However, GAE requests are currently failing with the message:
WARNING: Google App Engine does not support the use of proxies.
Can anyone advise a solution?
First of all, the Java 7 runtime is deprecated, so you should migrate to the Java 8 version. You can do it by specifying the Java 8 runtime in the appengine-web.xml file:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<runtime>java8</runtime>
<threadsafe>true</threadsafe>
</appengine-web-app>
There are other features that will change with the migration to Java 8. All the changes are explained here.
Just in case the error comes because of some issue in the configuration, please make sure the instance you are using as a proxy is correctly configured (using Squid is ok). The firewall rules and access control lists should be correctly established, such as:
gcloud compute firewall-rules create [FIREWALL_RULE] --network [NETWORK] --allow tcp:3128
You should also set the proper access control entries by enabling them in the Squid config. Here are some examples:
sudo sed -i 's:#\(http_access allow localnet\):\1:' /etc/squid/squid.conf
sudo sed -i 's:#\(http_access deny to_localhost\):\1:'/etc/squid/squid.conf
If you follow this example you can test the correct use of an instance used as a proxy server.
There is a static class in Java called ApiProxy (com.google.apphosting.api) that can be used as a collection point for all calls from user code to the application server. Here you can find all the classes and methods related to it, as well as other classes related to ApiProxy.

Azure Java SDK 1.0.0 osDiskStorageAccountType() returns null always

I started using Azure Java SDK 1.0.0 recently and I noticed that for a VM the method osDiskStorageAccountType() always returns null. The SDK is unable to even get information about the attached data disks.
From the article we know that osDiskStorageAccountType is only available for managed disk (this is c# based API but I think it will suitable for Java). Here is a snippet:
Gets the storage account type of the managed disk backing Os disk.
If you create Azure VM based on managed disk, it will give you related info.

How to launch a Virtual Machine in EC2 using Java

I am totally new to AWS. I have been given a official task to explore the AWS api for java So that we can launch a Virtual Machine ON EC2. I have gone through the official docs at sdk-for-java but having few doubts:
Would I need to deploy the java code on EC2 ?
Can Java code create and launch the Virtual Server or we can only start it through code and need to create the virtual machine through EC2 dashboard?
Thanks
First off, since you're very unfamiliar with AWS, have a read through their documentation. I know there's a lot there but the following links should directly apply to your situation:
Concepts
Getting started with AWS SDK for Java
Java examples
To answer your question, you want to start a virtual machine. Within AWS, these are referred to as "instances". To launch an instance using the API, you could execute the code that makes the API call locally and as long as you have valid credentials etc, the code should work. Your code does not need to be run inside of EC2.
The following code will run an EC2 instance for you as long as you have valid credentials and the AWS-SDK included in your java project.
RunInstancesRequest runInstancesRequest =
new RunInstancesRequest();
runInstancesRequest.withImageId("ami-4b814f22") // This is a base image, for example a ubuntu or linux instance
.withInstanceType("m1.small") // The size of the instance, these cost more the more powerful they are
.withMinCount(1) // Minimum amount of instances you want to launch
.withMaxCount(1); // Maximum amount of instances you want to launch

Atomated transfer of log file from amazon ec2 instance to local

How can I automatically transfer a log file which is present in amazon ec2 instance to my local machine. Can anyone give an idea about it. I would like to do it by a java API.
Currently I was using Chef "flume cookbook", but i was stuck at the part of automating it. And also that chef can be used in java APIs, so the process can be automated.

Categories