|
22 | 22 | import com.amazonaws.services.s3.model.GetObjectRequest;
|
23 | 23 | import com.amazonaws.services.s3.model.S3Object;
|
24 | 24 | import com.amazonaws.ClientConfiguration;
|
| 25 | +import com.amazonaws.AmazonServiceException; |
25 | 26 | import com.amazonaws.Protocol;
|
26 | 27 | import org.embulk.config.Config;
|
27 | 28 | import org.embulk.config.ConfigInject;
|
|
31 | 32 | import org.embulk.config.ConfigSource;
|
32 | 33 | import org.embulk.config.ConfigDiff;
|
33 | 34 | import org.embulk.config.TaskReport;
|
| 35 | +import org.embulk.config.ConfigException; |
34 | 36 | import org.embulk.spi.BufferAllocator;
|
35 | 37 | import org.embulk.spi.Exec;
|
36 | 38 | import org.embulk.spi.FileInputPlugin;
|
@@ -139,17 +141,29 @@ protected ClientConfiguration getClientConfiguration(PluginTask task)
|
139 | 141 |
|
140 | 142 | private FileList listFiles(PluginTask task)
|
141 | 143 | {
|
142 |
| - AmazonS3Client client = newS3Client(task); |
143 |
| - String bucketName = task.getBucket(); |
| 144 | + try { |
| 145 | + AmazonS3Client client = newS3Client(task); |
| 146 | + String bucketName = task.getBucket(); |
144 | 147 |
|
145 |
| - if (task.getPathPrefix().equals("/")) { |
146 |
| - log.info("Listing files with prefix \"/\". This doesn't mean all files in a bucket. If you intend to read all files, use \"path_prefix: ''\" (empty string) instead."); |
147 |
| - } |
| 148 | + if (task.getPathPrefix().equals("/")) { |
| 149 | + log.info("Listing files with prefix \"/\". This doesn't mean all files in a bucket. If you intend to read all files, use \"path_prefix: ''\" (empty string) instead."); |
| 150 | + } |
148 | 151 |
|
149 |
| - FileList.Builder builder = new FileList.Builder(task); |
150 |
| - listS3FilesByPrefix(builder, client, bucketName, |
151 |
| - task.getPathPrefix(), task.getLastPath()); |
152 |
| - return builder.build(); |
| 152 | + FileList.Builder builder = new FileList.Builder(task); |
| 153 | + listS3FilesByPrefix(builder, client, bucketName, |
| 154 | + task.getPathPrefix(), task.getLastPath()); |
| 155 | + return builder.build(); |
| 156 | + } |
| 157 | + catch (AmazonServiceException ex) { |
| 158 | + if (ex.getErrorType().equals(AmazonServiceException.ErrorType.Client)) { |
| 159 | + // HTTP 40x errors. auth error, bucket doesn't exist, etc. See AWS document for the full list: |
| 160 | + // http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html |
| 161 | + if (ex.getStatusCode() != 400) { // 404 Bad Request is unexpected error |
| 162 | + throw new ConfigException(ex); |
| 163 | + } |
| 164 | + } |
| 165 | + throw ex; |
| 166 | + } |
153 | 167 | }
|
154 | 168 |
|
155 | 169 | /**
|
|
0 commit comments