|
Project Information
|
Another Amazon AWS EC2 wrapper?Yes, this is yet another wrapper for Amazon EC2. There is nothing wrong with typica; I love this project, it help me get familiar with Amazon Services. Despite the REST hype, I still see SOAP + WS standards as a much more mature platform for enterprise development. Second, there needs to be an authority that keeps APIs in synch with latest Amazon AWS WSDLs. I would like to utilize my development team to help become such an authority, hopefully with your help. And by help I mean user community. Please use this API if you like it or not ;) Since all the projects we are involved in make use of Spring framework, we decided to make heavy use of it here as well. We are actively using Apache ServiceMix and Progress Fuse OSGi-containers, that is why the project is using Maven with PAX to create OSGi bundles. If you are not using OSGi, you can treat this library as a regular jar. We love Apache CXF (untill we ran into issues with EC2 WSDL and wsdl2java :)) and use it as to help out with SOAP stuff. Usage ExampleEC2 ec2 = (EC2) context.getBean("ec2");
InstanceStartupParameters params = new InstanceStartupParameters(AMAZON_WINDOWS_IMAGE_ID);
List<RunningInstance> instances = ec2.runInstances(params);
Assert.assertTrue("Only one instance should be returned", instances.size() == 1);
RunningInstance instance = instances.get(0);
Assert.assertTrue("Image id incorrect", instance.getImageId().equals(AMAZON_WINDOWS_IMAGE_ID));
for (int i=0; i < 20; i++) { //increase number of attempts, if you want to see instance launched
Thread.sleep(1000);
instance = ec2.describeInstance(instance.getId());
if (instance.getState() == InstanceState.RUNNING) {
break;
}
}
InstanceTerminationResult result = ec2.terminateInstance(instance.getId());
Assert.assertTrue("Instance should start terminating",
result.getShutdownState() == InstanceState.SHUTTING_DOWN || result.getShutdownState() == InstanceState.TERMINATED );Spring Configuration<!-- Expose properties. -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="aws.properties"/>
</bean>
<!-- Client Keystore Callback. -->
<bean id="clientKeystorePasswordCallback" class="com.netflexitysolutions.amazonws.ec2.security.ClientKeystorePasswordCallback">
<constructor-arg value="classpath:clientKeystore.properties"/>
</bean>
<!--
This bean is an Out interceptor which will add a timestamp,
sign the timestamp and body, and then encrypt the timestamp
and body. It uses 3DES as the symmetric key algorithm.
-->
<bean id="TimestampSignEncrypt_Request" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<constructor-arg>
<map>
<entry key="action" value="Timestamp Signature"/>
<!-- Encrypt - will hopefully be supported in next versions of AWS.-->
<entry key="user" value="${keystore.alias}"/>
<entry key="signaturePropFile" value="${signaturePropFile}"/>
<entry key="encryptionPropFile" value="${encryptionPropFile}"/>
<entry key="encryptionUser" value="${keystore.alias}"/>
<entry key="signatureKeyIdentifier" value="DirectReference"/>
<entry key="passwordCallbackRef" value-ref="clientKeystorePasswordCallback"/>
<entry key="signatureParts" value="${signatureParts}"/>
<!--
entry key="encryptionParts" value="{Element}{http://www.w3.org/2000/09/xmldsig#}Signature;{Content}{http://schemas.xmlsoap.org/soap/envelope/}Body"/>
<entry key="encryptionSymAlgorithm" value="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/>
-->
</map>
</constructor-arg>
</bean>
<!-- JAX-WS Client for Amazon AWS EC2 web service. -->
<jaxws:client id="amazonEC2Service" serviceClass="com.amazonaws.ec2.doc._2009_04_04.AmazonEC2PortType" address="${amazonaws.ec2.url}">
<jaxws:outInterceptors>
<ref bean="TimestampSignEncrypt_Request"/>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
</jaxws:outInterceptors>
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
</jaxws:inInterceptors>
</jaxws:client>
<!-- This is Netflexity EC2 client that you should use to call Amazon EC2. -->
<bean id="ec2" class="com.netflexitysolutions.amazonws.ec2.EC2Client">
<constructor-arg ref="amazonEC2Service"/>
</bean>aws.propertiesamazonaws.simpledb.url=https\://sdb.amazonaws.com
keystore.alias=REPLACEME
signaturePropFile=clientKeystore.properties
encryptionPropFile=clientKeystore.properties
signatureParts={Element}{http\://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;{Element}{http\://schemas.xmlsoap.org/soap/envelope/}BodyclientKeystore.propertiesorg.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin org.apache.ws.security.crypto.merlin.keystore.type=jks org.apache.ws.security.crypto.merlin.keystore.password=REPLACEME org.apache.ws.security.crypto.merlin.keystore.alias=REPLACEME org.apache.ws.security.crypto.merlin.file=awskeystore.jks awskeystore.jksThis is your java keystore file. Obviously, you can rename it, just make sure you update clientKeystore.properties accordingly. This is the most complex step of the entire setup. Unlike REST, SOAP needs a keystore file, composed of a pair: your Amazon x509 certificate (xxx.pem) and your Amazon private key. Unfortunatelly, java keygen utility cannot create a keystore using exising certificate + private key. To create, the keystore, please follow these instructions. In couple of days we will provide a utility that will simplify things. http://www.agentbob.info/agentbob/79-AB.html Contains Instructions http://www.slproweb.com/products/Win32OpenSSL.html Contains Windows OpenSSL install instructions. Here is what had to do:
|