AWS Java S3 Download Error: "profile file cannot be null"

I get an exception when I try to upload a file to Amazon S3 from my Java Spring application. The method is pretty simple:

private void productionFileSaver(String keyName, File f) throws InterruptedException { String bucketName = "{my-bucket-name}"; TransferManager tm = new TransferManager(new ProfileCredentialsProvider()); // TransferManager processes all transfers asynchronously, // so this call will return immediately. Upload upload = tm.upload( bucketName, keyName, new File("/mypath/myfile.png")); try { // Or you can block and wait for the upload to finish upload.waitForCompletion(); System.out.println("Upload complete."); } catch (AmazonClientException amazonClientException) { System.out.println("Unable to upload file, upload was aborted."); amazonClientException.printStackTrace(); } } 

This is basically the same as amazon provides here , and the same exception with exactly the same message ("profile file cannot be null") appears when trying this other version . The problem is not related to a file that does not exist or is null (I already checked a thousand ways that the File argument obtained by the TransferManager.upload method exists before it is called).

I can not find any information about my exception message " profile file cannot be null ". The first lines of the error log are as follows:

 com.amazonaws.AmazonClientException: Unable to complete transfer: profile file cannot be null at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.unwrapExecutionException(AbstractTransfer.java:281) at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.rethrowExecutionException(AbstractTransfer.java:265) at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.waitForCompletion(AbstractTransfer.java:103) at com.fullteaching.backend.file.FileController.productionFileSaver(FileController.java:371) at com.fullteaching.backend.file.FileController.handlePictureUpload(FileController.java:247) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) 

My S3 policy allows you to create and install objects for all types of users.

Any idea what is going on?

+7
java amazon amazon-s3
source share
2 answers

ProfileCredentialsProvider () creates a new profile credential provider that returns the AWS security credentials configured for the default profile.

So, if you do not have a configuration for the default profile in ~/.aws/credentials , when you try to place the object, this will lead to an error.

If you run your code in the Lambda service, it will not provide this file. In this case, you also do not need to provide credentials. Just assign the correct IAM role to your lambda function, then using the default constructor should solve the problem.

You might want to change the TransferManager constructor to suit your needs.

+9
source share

The solution was quite simple: I tried to implement this post without AmazonS3 bean for Spring.

This link will help with the configuration:

http://codeomitted.com/upload-file-to-s3-with-spring/

+3
source share

All Articles