aws-java-sdk-x.y/lib/aws-java-sdk-x.y.jar
in your CLASSPATH
http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-install.html
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html
com.amazonaws
com.amazonaws.auth
com.amazonaws.services.<service>
AmazonXXXClient
: synchronous interfaceAmazonXXXClientAsync
: asynchronous interfacecom.amazonaws.auth.AWSCredentials
BasicAWSCredentials(String accessKey, String secretKey)
PropertiesCredentials(File file)
com.amazonaws.auth.AWSCredentialsProvider
AWSCredentialsProviderChain(AWSCredentialsProvider ...credentialsProviders)
(a
sort of wallet for credentials)ClasspathPropertiesFileCredentialsProvider
(uses a Java properties file in the CP)SystemPropertiesCredentialsProvider
(uses Java propertiesEnvironmentVariableCredentialsProvider
(uses env. vars)ProfileCredentialsProvider
(uses same profiles as AWS CLI)AWSCredentials = new DefaultAWSCredentialsProviderChain();
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
AWSCredentials credentials = new ProfileCredentialsProvider().getCredentials();
<service>Client
object for a given region and manipulate itAWSCredentials
or AWSCredentialsProvider
ClientConfiguration
: configures the underlying REST client (proxy, retries,
timeout, protocols (HTTP/HTTPS)Examples:
ec2 = new AmazonEC2Client(credentials);
s3 = new AmazonS3Client(credentials);
A Request
object represents a HTTP request through which you provide arguments
Create<what>Request
, Describe<what>Request
, Delete<what>Request
Examples:
CreateSecurityGroupRequest
A Result
object represents a HTTP response
Examples:
CreateSecurityGroupResult
CreateInstanceResult
Package com.amazonaws.services.<service>.model
Package com.amazonaws.regions
regions.Region
lists all regionsregions.Region
/regions.RegionUtils
:
eu-west-1
)1// Get the reservation 2DescribeInstancesRequest request = new DescribeInstancesRequest(); 3Filter filter = new Filter('tag:name', Arrays.asList('prod')); 4request.setFilters(Arrays.asList(filter)); 5DescribeInstancesResult res = ec2.describeInstances(request); 6List<Reservation> reservations = result.getReservations(); 7Reservation resa = reservations[0]; 8// Get the instance 9instance = resa[0]; 10instance.terminate(); 11// Or terminate all instances 12resa.terminate_all();
1// Add a rule 2IpPermission ssh = new IpPermission(); 3ssh.withFromPort(22).withToPort(22).withIpRanges('0.0.0.0/0'); 4IpPermission http = new IpPermission(); 5http.withFromPort(80).withToPort(80).withIpRanges('0.0.0.0/0'); 6List<IpPermission> perms = Arrays.asList(ssh, http); 7AuthorizeSecurityGroupIngressRequest request = new authorizeSecurityGroupIngressRequest('ssh-access', perms);
An Elastic Load Balancer is a server that receives client connections and forwards them to a pool of instances based on defined rules.
Instances can be added or removed from the pool based on their health and auto-scaling policies.
HTTP:8080/health
A web server must serve http://<ip>:8080/health
1List<String> zones = Arrays.asList('eu-west-1a', 'eu-west-1b'); 2Listener http = new Listener('http', 80, 8080); 3Listener https = new Listener('https', 443, 8443); 4List<Listener> listeners = Arrays.asList(http, https); 5CreateLoadBalancerRequest request = 6 new CreateLoadBalancerRequest('lb1', listeners, zones); 7CreateLoadBalancerResult res = elb.createLoadBalancer(request);
The listener provides network translation from the client to an instance. Its frontend is limited to ports 25, 80, 443, 465, 587 and 1024-65535. Its backend (instance) can listen to any port.