AWS S3 - Consumer Examples
MoveAfterRead consumer option
In addition to deleteAfterRead, it has been added another option, moveAfterRead. With this option enabled, the consumed object will be moved to a target destinationBucket instead of being only deleted. This will require specifying the destinationBucket option. As example:
-
Java
-
XML
-
YAML
from("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&moveAfterRead=true&destinationBucket=myothercamelbucket")
.to("mock:result"); <route>
<from uri="aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&moveAfterRead=true&destinationBucket=myothercamelbucket"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: aws2-s3://mycamelbucket
parameters:
amazonS3Client: "#amazonS3Client"
moveAfterRead: true
destinationBucket: myothercamelbucket
steps:
- to:
uri: mock:result In this case, the objects consumed will be moved to myothercamelbucket bucket and deleted from the original one (because of deleteAfterRead set to true as default).
You have also the possibility of using a key prefix/suffix while moving the file to a different bucket. The options are destinationBucketPrefix and destinationBucketSuffix.
Both options support the Simple expression language. Wrap an expression in RAW() to prevent the Camel URI parser from interpreting special characters:
-
Java
-
XML
-
YAML
from("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&moveAfterRead=true&destinationBucket=myothercamelbucket&destinationBucketPrefix=RAW(pre-)&destinationBucketSuffix=RAW(-suff)")
.to("mock:result"); <route>
<from uri="aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&moveAfterRead=true&destinationBucket=myothercamelbucket&destinationBucketPrefix=RAW(pre-)&destinationBucketSuffix=RAW(-suff)"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: aws2-s3://mycamelbucket
parameters:
amazonS3Client: "#amazonS3Client"
moveAfterRead: true
destinationBucket: myothercamelbucket
destinationBucketPrefix: "RAW(pre-)"
destinationBucketSuffix: "RAW(-suff)"
steps:
- to:
uri: mock:result In this case, an object named test is moved to myothercamelbucket with the key pre-test-suff.
Using a Simple expression, you can build dynamic paths at runtime. The following example organises moved objects by date:
-
Java
-
XML
-
YAML
from("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&moveAfterRead=true&destinationBucket=myothercamelbucket&destinationBucketPrefix=RAW(${date:now:yyyy/MM/dd}/)")
.to("mock:result"); <route>
<from uri="aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&moveAfterRead=true&destinationBucket=myothercamelbucket&destinationBucketPrefix=RAW(${date:now:yyyy/MM/dd}/)"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: aws2-s3://mycamelbucket
parameters:
amazonS3Client: "#amazonS3Client"
moveAfterRead: true
destinationBucket: myothercamelbucket
destinationBucketPrefix: "RAW(${date:now:yyyy/MM/dd}/)"
steps:
- to:
uri: mock:result An object named report.csv consumed on 2026-05-19 is moved with the key 2026/05/19/report.csv. Expressions are evaluated once per exchange, so each message can produce a different destination key.
Consumer with prefix filtering
You can configure the consumer to only process objects with a specific prefix:
-
Java
-
XML
-
YAML
from("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&prefix=processed/&delay=30000")
.to("mock:result"); <route>
<from uri="aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&prefix=processed/&delay=30000"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: aws2-s3://mycamelbucket
parameters:
amazonS3Client: "#amazonS3Client"
prefix: processed/
delay: 30000
steps:
- to:
uri: mock:result This will only consume objects that start with "processed/" prefix from the mycamelbucket bucket, with a 30-second polling delay.
Consumer with custom polling and batch settings
Configure custom polling intervals and batch sizes:
-
Java
-
XML
-
YAML
from("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&delay=60000&maxMessagesPerPoll=5&includeBody=false")
.to("mock:result"); <route>
<from uri="aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&delay=60000&maxMessagesPerPoll=5&includeBody=false"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: aws2-s3://mycamelbucket
parameters:
amazonS3Client: "#amazonS3Client"
delay: 60000
maxMessagesPerPoll: 5
includeBody: false
steps:
- to:
uri: mock:result This consumer polls every 60 seconds, processes up to 5 objects per poll, and doesn’t include the object body in the message (only metadata).
Consumer with file filtering and no deletion
Configure the consumer to not delete files after reading and include specific file patterns:
-
Java
-
XML
-
YAML
from("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&deleteAfterRead=false&fileName=*.pdf")
.to("mock:result"); <route>
<from uri="aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&deleteAfterRead=false&fileName=*.pdf"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: aws2-s3://mycamelbucket
parameters:
amazonS3Client: "#amazonS3Client"
deleteAfterRead: false
fileName: "*.pdf"
steps:
- to:
uri: mock:result This consumer will read PDF files but won’t delete them after processing.
Consumer with done file pattern
Use a done file pattern to ensure files are completely uploaded before processing:
-
Java
-
XML
-
YAML
from("aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&doneFileName=*.done")
.to("mock:result"); <route>
<from uri="aws2-s3://mycamelbucket?amazonS3Client=#amazonS3Client&doneFileName=*.done"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: aws2-s3://mycamelbucket
parameters:
amazonS3Client: "#amazonS3Client"
doneFileName: "*.done"
steps:
- to:
uri: mock:result This consumer will only process files when a corresponding .done file exists in the bucket.