AWS S3 under java development of

Set AWS credentials

 

method one:

Amazon 3s default authentication using a local file, idea development, need to download plug-ins

 

 . Also required on Windows C:\Users\USERNAME\.aws\credentials

 

Note: This method is the recommended way, but you need to modify the local configuration, linux server you need to configure the environment variables

Second way:

A distinguished manner, the code information is directly related to the configuration

/ ** 
 * the ACCESSKEY 
 * / 
Private  static  Final String the ACCESSKEY = "xxxxxx" ;
 / ** 
 * SecretKey 
 * / 
Private  static  Final String SecretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ;
 / ** 
 * bucket name 
 * / 
Private  static  Final String = BUCKET_NAME " since barrels name "defined ;
 / ** 
 * create Object s3 
 * / 
Private  static  Final BasicAWSCredentials awsCreds = new new BasicAWSCredentials (the ACCESSKEY, SecretKey);
 Private  static  Final AmazonS3 s3 = AmazonS3ClientBuilder.standard()
        .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
        .withRegion(Regions.DEFAULT_REGION)
        .build();

 

The official document: https://docs.aws.amazon.com/zh_cn/sdk-for-java/v2/developer-guide/setup-credentials.html

Official Code Example S3: https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/example_code/s3/src/main/java/com/example/s3

 

Simple demo of git Address: https://github.com/Zzoser/zoser.upload.demo

 

Guess you like

Origin www.cnblogs.com/Zorser/p/11578234.html