Install the SDK
The recommended way to use the AWS SDK for Java in your project is to consume it from Maven. Import the aws-java-sdk-bom and specify the SDK Maven modules that your project needs in the dependencies.
Importing the BOM
com.amazonaws
aws-java-sdk-bom
1.11.63
pom
import
Using the SDK Maven modules
com.amazonaws
aws-java-sdk-ec2
com.amazonaws
aws-java-sdk-s3
com.amazonaws
aws-java-sdk-dynamodb
See the Set up the AWS SDK for Javasection of the developer guide for more information about installing the SDK through other means.
Features
Provides easy-to-use HTTP clients for all supported AWS services, regions, and authentication protocols.
Client-Side Data Encryption for Amazon S3 - Helps improve the security of storing application data in Amazon S3.
Amazon DynamoDB Object Mapper - Uses Plain Old Java Object (POJOs) to store and retrieve Amazon DynamoDB data.
Amazon S3 Transfer Manager - With a simple API, achieve enhanced the throughput, performance, and reliability by using multi-threaded Amazon S3 multipart calls.
Amazon SQS Client-Side Buffering - Collect and send SQS requests in asynchronous batches, improving application and network performance.
Automatically uses IAM Instance Profile Credentials on configured Amazon EC2 instances.
And more!
Building From Source
Once you check out the code from GitHub, you can build it using Maven. To disable the GPG-signing in the build, use:
mvn clean install -Dgpg.skip=true
Supported Versions
1.11.x - Recommended.
1.10.x - Approved. Only major critical bugs will be fixed. To get the new features, upgrade to 1.11.x version of the SDK.
https://github.com/helloworldtang/aws-sdk-java
/** Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
*http://aws.amazon.com/apache2.0*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.*/
importjava.io.BufferedReader;importjava.io.File;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.io.OutputStreamWriter;importjava.io.Writer;importjava.util.UUID;importcom.amazonaws.AmazonClientException;importcom.amazonaws.AmazonServiceException;importcom.amazonaws.auth.AWSCredentials;importcom.amazonaws.auth.profile.ProfileCredentialsProvider;importcom.amazonaws.regions.Region;importcom.amazonaws.regions.Regions;importcom.amazonaws.services.s3.AmazonS3;importcom.amazonaws.services.s3.AmazonS3Client;importcom.amazonaws.services.s3.model.Bucket;importcom.amazonaws.services.s3.model.GetObjectRequest;importcom.amazonaws.services.s3.model.ListObjectsRequest;importcom.amazonaws.services.s3.model.ObjectListing;importcom.amazonaws.services.s3.model.PutObjectRequest;importcom.amazonaws.services.s3.model.S3Object;importcom.amazonaws.services.s3.model.S3ObjectSummary;/*** This sample demonstrates how to make basic requests to Amazon S3 using the
* AWS SDK for Java.
*
* Prerequisites: You must have a valid Amazon Web Services developer
* account, and be signed up to use Amazon S3. For more information on Amazon
* S3, seehttp://aws.amazon.com/s3.*
* Fill in your AWS access credentials in the provided credentials file
* template, and be sure to move the file to the default location
* (~/.aws/credentials) where the sample code will load the credentials from.
*
* WARNING: To avoid accidental leakage of your credentials, DO NOT keep
* the credentials file in your source directory.
*
*http://aws.amazon.com/security-credentials
*/
public classS3Sample {public static void main(String[] args) throwsIOException {/** The ProfileCredentialsProvider will return your [default]
* credential profile by reading from the credentials file located at
* (~/.aws/credentials).*/AWSCredentials credentials= null;try{
credentials= newProfileCredentialsProvider().getCredentials();
}catch(Exception e) {throw newAmazonClientException("Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}
AmazonS3 s3= newAmazonS3Client(credentials);
Region usWest2=Region.getRegion(Regions.US_WEST_2);
s3.setRegion(usWest2);
String bucketName= "my-first-s3-bucket-" +UUID.randomUUID();
String key= "MyObjectKey";//key可以以目录的形式出现a/b,则会在a目录下创建b文件