├── .gitignore ├── LICENSE.txt ├── README.md ├── pom.xml └── src ├── main └── resources │ ├── META-INF │ └── maven │ │ └── archetype-metadata.xml │ └── archetype-resources │ ├── README.html │ ├── pom.xml │ └── src │ └── main │ └── java │ └── AwsSdkSample.java └── test └── resources └── projects └── basic ├── archetype.properties └── goal.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /.project 2 | /.settings 3 | /target -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | 4 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 5 | 6 | 1. Definitions. 7 | 8 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 9 | 10 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 11 | 12 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 13 | 14 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 15 | 16 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 17 | 18 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 19 | 20 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 21 | 22 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 23 | 24 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 25 | 26 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 27 | 28 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 29 | 30 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 31 | 32 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 33 | 34 | 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and 35 | 2. You must cause any modified files to carry prominent notices stating that You changed the files; and 36 | 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 37 | 4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 38 | 39 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 40 | 41 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 42 | 43 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 44 | 45 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 46 | 47 | 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 48 | 49 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 50 | 51 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | aws-sdk-java-archetype 2 | ====================== 3 | 4 | The AWS SDK for Java Maven archetype allows you to easily create new Java projects configured with the [AWS SDK for Java](http://aws.amazon.com/sdkforjava/) and some sample code to help you find your way around the SDK. 5 | 6 | Starting a project from the archetype is easy: 7 |
 8 | mvn archetype:generate \
 9 |      -DarchetypeGroupId=com.amazonaws \
10 |      -DarchetypeArtifactId=aws-java-sdk-archetype
11 | 
12 | 13 | When you run the Maven archetype:generate goal, you'll be prompted for some basic Maven values for your new project (groupId, artifactId, version). 14 | 15 |
16 | [INFO] Generating project in Interactive mode
17 | [INFO] Archetype [com.amazonaws:aws-java-sdk-archetype:1.0.0] found in catalog local
18 | Define value for property 'groupId': : com.foo   
19 | Define value for property 'artifactId': : my-aws-java-project
20 | Define value for property 'version':  1.0-SNAPSHOT: : 
21 | Define value for property 'package':  com.foo: : 
22 | 
23 | 24 | When the archetype:generate goal completes, you'll have a new Maven Java project, already configured with a dependency on the AWS SDK for Java and some sample code in the project to help you get started with the SDK. 25 | 26 | Before you run the sample code, you'll need to fill in your AWS security credentials. This sample loads your credentials from the default credentials profiles file (~/.aws/credentials). If you've already set up your profile credentials file, then you're ready to run the sample. If you haven't set up your ~/.aws/credentials file yet, here's what you should start with: 27 |
28 | [default]
29 | aws_access_key_id     = 
30 | aws_secret_access_key = 
31 | 
32 | 33 | When your AWS security credentials are configured, you're ready to compile and run the new project. The sample project's POM file is configured so that you can easily compile, jar, and run the project by executing mvn package exec:java. 34 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.amazonaws 7 | aws-java-sdk-archetype 8 | 1.0.1 9 | maven-archetype 10 | AWS SDK for Java Archetype 11 | Maven archetype for a simple AWS Java application. 12 | https://aws.amazon.com/sdkforjava 13 | 14 | 15 | https://github.com/aws/aws-java-sdk-archetype.git 16 | 17 | 18 | 19 | 20 | Apache License, Version 2.0 21 | https://aws.amazon.com/apache2.0 22 | repo 23 | 24 | 25 | 26 | 27 | 28 | amazonwebservices 29 | Amazon Web Services 30 | https://aws.amazon.com 31 | 32 | developer 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.apache.maven.archetype 42 | archetype-packaging 43 | 2.2 44 | 45 | 46 | 47 | 48 | 49 | 50 | maven-archetype-plugin 51 | 2.2 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | publishing 60 | 61 | 62 | 63 | 64 | org.apache.maven.plugins 65 | maven-gpg-plugin 66 | 67 | 68 | sign-artifacts 69 | verify 70 | 71 | sign 72 | 73 | 74 | 75 | 76 | 77 | 78 | org.sonatype.plugins 79 | nexus-staging-maven-plugin 80 | 1.5.1 81 | true 82 | 83 | sonatype-nexus-staging 84 | https://oss.sonatype.org 85 | true 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/maven/archetype-metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | src/main/java 8 | 9 | **/*.java 10 | 11 | 12 | 13 | src/main/resources 14 | 15 | **/*.properties 16 | 17 | 18 | 19 | .settings 20 | 21 | **/*.prefs 22 | 23 | 24 | 25 | 26 | 27 | README.html 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/resources/archetype-resources/README.html: -------------------------------------------------------------------------------- 1 | #set( $symbol_pound = '#' ) 2 | #set( $symbol_dollar = '$' ) 3 | #set( $symbol_escape = '\' ) 4 | 5 | 6 | 7 | 8 | AWS SDK for Java Sample 9 | 101 | 102 | 103 |

AWS SDK for Java Sample

104 | This sample demonstrates how to make basic requests to AWS services using the AWS SDK for Java. 105 |

106 | For lots more information on using the AWS SDK for Java, including information on high-level APIs 107 | and advanced features, check out the 108 | AWS SDK for Java Developer Guide. 109 | 110 |

111 | Stay up to date with new features in the AWS SDK for Java by following the 112 | AWS Java Developer Blog. 113 | 114 |

Prerequisites

115 | 119 |

Running the Sample

120 |
    121 |
  1. Configure your AWS security credentials in a .aws/credentials file in your home directory. For example: 122 |
    123 |   [default]
    124 |   aws_access_key_id     = <your AWS access key>
    125 |   aws_secret_access_key = <your AWS secret access key>
    126 | 
    127 | 128 | More information on configuring ~/.aws/config

    129 |
  2. 130 |
  3. Run mvn package exec:java to build and run the AwsSdkSample class.
  4. 131 |
132 | 133 | 134 | -------------------------------------------------------------------------------- /src/main/resources/archetype-resources/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | ${groupId} 6 | ${artifactId} 7 | ${version} 8 | jar 9 | 10 | AWS SDK for Java Sample 11 | http://aws.amazon.com/sdkforjava 12 | 13 | 14 | 15 | com.amazonaws 16 | aws-java-sdk 17 | [1.7.2,2.0.0) 18 | 19 | 20 | 21 | 22 | 23 | 24 | org.codehaus.mojo 25 | exec-maven-plugin 26 | 1.2.1 27 | 28 | 29 | 30 | java 31 | 32 | 33 | 34 | 35 | AwsSdkSample 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/resources/archetype-resources/src/main/java/AwsSdkSample.java: -------------------------------------------------------------------------------- 1 | #set( $symbol_pound = '#' ) 2 | #set( $symbol_dollar = '$' ) 3 | #set( $symbol_escape = '\' ) 4 | /* 5 | * Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"). 8 | * You may not use this file except in compliance with the License. 9 | * A copy of the License is located at 10 | * 11 | * http://aws.amazon.com/apache2.0 12 | * 13 | * or in the "license" file accompanying this file. This file is distributed 14 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 15 | * express or implied. See the License for the specific language governing 16 | * permissions and limitations under the License. 17 | */ 18 | import java.io.File; 19 | import java.util.HashSet; 20 | import java.util.List; 21 | import java.util.Set; 22 | 23 | import com.amazonaws.AmazonClientException; 24 | import com.amazonaws.AmazonServiceException; 25 | import com.amazonaws.auth.AWSCredentialsProvider; 26 | import com.amazonaws.auth.profile.ProfileCredentialsProvider; 27 | import com.amazonaws.auth.profile.ProfilesConfigFile; 28 | import com.amazonaws.services.ec2.AmazonEC2; 29 | import com.amazonaws.services.ec2.AmazonEC2Client; 30 | import com.amazonaws.services.ec2.model.AvailabilityZone; 31 | import com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult; 32 | import com.amazonaws.services.ec2.model.DescribeInstancesResult; 33 | import com.amazonaws.services.ec2.model.Instance; 34 | import com.amazonaws.services.ec2.model.Reservation; 35 | import com.amazonaws.services.s3.AmazonS3; 36 | import com.amazonaws.services.s3.AmazonS3Client; 37 | import com.amazonaws.services.s3.iterable.S3Objects; 38 | import com.amazonaws.services.s3.model.Bucket; 39 | import com.amazonaws.services.s3.model.S3ObjectSummary; 40 | 41 | /** 42 | * This class is a starting point for working with the AWS SDK for Java, and 43 | * shows how to make a few simple requests to Amazon EC2 and Amazon S3. 44 | * 45 | * Before you run this code, be sure to fill in your AWS security credentials 46 | * in the .aws/credentials file under your home directory. 47 | * 48 | * If you don't have an Amazon Web Services account, you can get started for free: 49 | * http://aws.amazon.com/free 50 | * 51 | * For lots more information on using the AWS SDK for Java, including information on 52 | * high-level APIs and advanced features, check out the AWS SDK for Java Developer Guide: 53 | * http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/welcome.html 54 | * 55 | * Stay up to date with new features in the AWS SDK for Java by following the 56 | * AWS Java Developer Blog: 57 | * https://java.awsblog.com 58 | */ 59 | public class AwsSdkSample { 60 | 61 | /* 62 | * Important: Be sure to fill in your AWS access credentials in the 63 | * .aws/credentials file under your home directory 64 | * before you run this sample. 65 | * http://aws.amazon.com/security-credentials 66 | */ 67 | static AmazonEC2 ec2; 68 | static AmazonS3 s3; 69 | 70 | 71 | /** 72 | * The only information needed to create a client are security credentials - 73 | * your AWS Access Key ID and Secret Access Key. All other 74 | * configuration, such as the service endpoints have defaults provided. 75 | * 76 | * Additional client parameters, such as proxy configuration, can be specified 77 | * in an optional ClientConfiguration object when constructing a client. 78 | * 79 | * @see com.amazonaws.auth.BasicAWSCredentials 80 | * @see com.amazonaws.auth.PropertiesCredentials 81 | * @see com.amazonaws.ClientConfiguration 82 | */ 83 | private static void init() throws Exception { 84 | /* 85 | * ProfileCredentialsProvider loads AWS security credentials from a 86 | * .aws/config file in your home directory. 87 | * 88 | * These same credentials are used when working with other AWS SDKs and the AWS CLI. 89 | * 90 | * You can find more information on the AWS profiles config file here: 91 | * http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html 92 | */ 93 | File configFile = new File(System.getProperty("user.home"), ".aws/credentials"); 94 | AWSCredentialsProvider credentialsProvider = new ProfileCredentialsProvider( 95 | new ProfilesConfigFile(configFile), "default"); 96 | 97 | if (credentialsProvider.getCredentials() == null) { 98 | throw new RuntimeException("No AWS security credentials found:\n" 99 | + "Make sure you've configured your credentials in: " + configFile.getAbsolutePath() + "\n" 100 | + "For more information on configuring your credentials, see " 101 | + "http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html"); 102 | } 103 | 104 | ec2 = new AmazonEC2Client(credentialsProvider); 105 | s3 = new AmazonS3Client(credentialsProvider); 106 | } 107 | 108 | 109 | public static void main(String[] args) throws Exception { 110 | System.out.println("==========================================="); 111 | System.out.println("Welcome to the AWS Java SDK!"); 112 | System.out.println("==========================================="); 113 | 114 | init(); 115 | 116 | try { 117 | /* 118 | * The Amazon EC2 client allows you to easily launch and configure 119 | * computing capacity in AWS datacenters. 120 | * 121 | * In this sample, we use the EC2 client to list the availability zones 122 | * in a region, and then list the instances running in those zones. 123 | */ 124 | DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones(); 125 | List availabilityZones = availabilityZonesResult.getAvailabilityZones(); 126 | System.out.println("You have access to " + availabilityZones.size() + " availability zones:"); 127 | for (AvailabilityZone zone : availabilityZones) { 128 | System.out.println(" - " + zone.getZoneName() + " (" + zone.getRegionName() + ")"); 129 | } 130 | 131 | DescribeInstancesResult describeInstancesResult = ec2.describeInstances(); 132 | Set instances = new HashSet(); 133 | for (Reservation reservation : describeInstancesResult.getReservations()) { 134 | instances.addAll(reservation.getInstances()); 135 | } 136 | 137 | System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running."); 138 | 139 | 140 | /* 141 | * The Amazon S3 client allows you to manage and configure buckets 142 | * and to upload and download data. 143 | * 144 | * In this sample, we use the S3 client to list all the buckets in 145 | * your account, and then iterate over the object metadata for all 146 | * objects in one bucket to calculate the total object count and 147 | * space usage for that one bucket. Note that this sample only 148 | * retrieves the object's metadata and doesn't actually download the 149 | * object's content. 150 | * 151 | * In addition to the low-level Amazon S3 client in the SDK, there 152 | * is also a high-level TransferManager API that provides 153 | * asynchronous management of uploads and downloads with an easy to 154 | * use API: 155 | * http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/TransferManager.html 156 | */ 157 | List buckets = s3.listBuckets(); 158 | System.out.println("You have " + buckets.size() + " Amazon S3 bucket(s)."); 159 | 160 | if (buckets.size() > 0) { 161 | Bucket bucket = buckets.get(0); 162 | 163 | long totalSize = 0; 164 | long totalItems = 0; 165 | /* 166 | * The S3Objects and S3Versions classes provide convenient APIs 167 | * for iterating over the contents of your buckets, without 168 | * having to manually deal with response pagination. 169 | */ 170 | for (S3ObjectSummary objectSummary : S3Objects.inBucket(s3, bucket.getName())) { 171 | totalSize += objectSummary.getSize(); 172 | totalItems++; 173 | } 174 | 175 | System.out.println("The bucket '" + bucket.getName() + "' contains "+ totalItems + " objects " 176 | + "with a total size of " + totalSize + " bytes."); 177 | } 178 | } catch (AmazonServiceException ase) { 179 | /* 180 | * AmazonServiceExceptions represent an error response from an AWS 181 | * services, i.e. your request made it to AWS, but the AWS service 182 | * either found it invalid or encountered an error trying to execute 183 | * it. 184 | */ 185 | System.out.println("Error Message: " + ase.getMessage()); 186 | System.out.println("HTTP Status Code: " + ase.getStatusCode()); 187 | System.out.println("AWS Error Code: " + ase.getErrorCode()); 188 | System.out.println("Error Type: " + ase.getErrorType()); 189 | System.out.println("Request ID: " + ase.getRequestId()); 190 | } catch (AmazonClientException ace) { 191 | /* 192 | * AmazonClientExceptions represent an error that occurred inside 193 | * the client on the local host, either while trying to send the 194 | * request to AWS or interpret the response. For example, if no 195 | * network connection is available, the client won't be able to 196 | * connect to AWS to execute a request and will throw an 197 | * AmazonClientException. 198 | */ 199 | System.out.println("Error Message: " + ace.getMessage()); 200 | } 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /src/test/resources/projects/basic/archetype.properties: -------------------------------------------------------------------------------- 1 | #Wed Feb 12 13:43:30 PST 2014 2 | package=it.pkg 3 | version=0.1-SNAPSHOT 4 | groupId=archetype.it 5 | artifactId=basic 6 | -------------------------------------------------------------------------------- /src/test/resources/projects/basic/goal.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/aws-sdk-java-archetype/396aae2fad854988b6b78d373b95709ce01f66e2/src/test/resources/projects/basic/goal.txt --------------------------------------------------------------------------------