AWS S3 Storage Service
Since Camel 3.2
Both producer and consumer are supported
The AWS2 S3 component supports storing and retrieving objects from/to Amazon’s S3 service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon S3. More information is available at Amazon S3.
URI Format
aws2-s3://bucketNameOrArn[?options]
The bucket will be created if it doesn’t already exist.
You can append query options to the URI in the following format:
?options=value&option2=value&…
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The AWS S3 Storage Service component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Whether to create the bucket (CreateBucket) when the endpoint starts and HeadBucket answers that it does not exist. With moveAfterRead, the consumer also creates the destinationBucket. When false, a missing bucket is not created, and the operations on it fail. Not used when fileName is set. | false | boolean | |
The component configuration. | AWS2S3Configuration | ||
The delimiter of the ListObjectsV2 request of the consumer and of the listObjects operation, where the CamelAwsS3Delimiter header replaces it. S3 groups the keys that contain the delimiter after the prefix into common prefixes and does not return them as objects: for example the delimiter / with the prefix logs/ lists only the objects directly under logs/, not those under logs/2024/. | String | ||
Whether the S3 client uses path-style requests, with the bucket name in the path of the URL (https://s3.eu-west-1.amazonaws.com/mybucket/key), instead of virtual-hosted-style requests, with the bucket name in the host name (https://mybucket.s3.eu-west-1.amazonaws.com/key). Many S3-compatible stores used with uriEndpointOverride need it. | false | boolean | |
Whether to get only the metadata of the objects, without their content: the consumer and the getObject operation send a HeadObject request instead of GetObject, set the same headers, and set no body (the consumer) or keep the body (getObject). The headBucket operation then keeps the body too. It takes precedence over includeBody. | false | boolean | |
Whether the S3 client sends the requests to the URI of the uriEndpointOverride option instead of the S3 endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
Whether the producer operations take their request from the message body: the request of the AWS SDK for the operation, such as a GetObjectRequest for getObject or a ListObjectsV2Request for listObjects. The upload (no operation), listBuckets, headBucket, headObject, createDownloadLink and createUploadLink do not use it. | false | boolean | |
A bucket policy, as JSON, that the endpoint sets on the bucket with PutBucketPolicy when it starts. It is set only when the bucket does not exist yet, after autoCreateBucket created it: the policy of an existing bucket is not changed. | String | ||
Only the objects whose key begins with this prefix are listed: by the consumer (the Prefix of its ListObjectsV2 request) and by the listObjects operation, where the CamelAwsS3Prefix header replaces it. The removePrefixOnMove option also uses it. | String | ||
The ID of the AWS region of the S3 client, in lower case, for example eu-west-1 (the value of Region.EU_WEST_1.id()). autoCreateBucket creates the bucket in this region. If not set, the AWS SDK resolves the region itself, for example from the AWS_REGION environment variable. Enum values:
| String | ||
The URI that the S3 client sends the requests to, for example http://localhost:9000 for a local S3-compatible store. The client uses it only when overrideEndpoint is true, while the presigner of createDownloadLink and createUploadLink uses it whenever it is set. | String | ||
The encryption algorithm of SSE-C, used when useCustomerKey is true. S3 supports only AES256. | String | ||
The customer-provided key of SSE-C, used when useCustomerKey is true: the 256-bit key itself, base64-encoded, not an ID. In an endpoint URI, use RAW() around it, as a base64 value can contain + and / characters. | String | ||
The base64-encoded 128-bit MD5 digest of the customer-provided key of customerKeyId, which S3 uses to check that it received the key without error. Used when useCustomerKey is true. | String | ||
Whether to use server-side encryption with a customer-provided key (SSE-C), the key of the customerKeyId, customerKeyMD5 and customerAlgorithm options. The key is sent with the get of each consumed object, and by the producer with PutObject, multipart uploads (also in streaming upload mode), getObject, getObjectRange and copyObject (for the source and the copy). S3 needs the same key to read an object stored with it. | false | boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether to delete each consumed object from the bucket after its exchange completes successfully. If the exchange fails, the object is not deleted, and a later poll consumes it again. When false, the polls consume the same objects again and again: use the Idempotent Consumer EIP to filter out the duplicates, for example on the CamelAwsS3Key header. With moveAfterRead, the object is deleted after it is copied. | true | boolean | |
The bucket that moveAfterRead copies the consumed objects to. The consumer checks at startup that it exists, and creates it when autoCreateBucket is true. | String | ||
A prefix that moveAfterRead puts before the key of the object in the destinationBucket, for example archive/. It can be a Simple expression, evaluated with the exchange of the object. | String | ||
A suffix that moveAfterRead appends to the key of the object in the destinationBucket, after its extension, for example .processed. It can be a Simple expression, evaluated with the exchange of the object. | String | ||
The key of a done file: when it is set, a poll consumes objects only when an object with this key exists in the bucket (checked with HeadObject at the start of each poll). It is one fixed key, not a pattern. The done file is listed and consumed like the other objects, unless the prefix option leaves it out. | String | ||
The key of the one object to consume. When it is set, each poll gets this object instead of listing the bucket, and the endpoint does not check at startup that the bucket exists (so autoCreateBucket and policy are not applied). | String | ||
Whether the consumer reads the content of each object into the message body as a byte array, and then closes the object stream. When false, the body is the object stream itself (a ResponseInputStream of the AWS SDK), which holds an HTTP connection of the S3 client until it is closed: autocloseBody closes it when the exchange completes, otherwise the route must close it. ignoreBody takes precedence over this option. | true | boolean | |
Whether the consumer consumes the folder objects, the objects whose Content-Type is application/x-directory (such as the S3 console creates for a folder). When false, they are skipped and stay in the bucket. | true | boolean | |
Whether to copy each consumed object to the destinationBucket after its exchange completes successfully, with the key destinationBucketPrefix + key + destinationBucketSuffix. The object is removed from the bucket only by deleteAfterRead (true by default): with deleteAfterRead false, it is copied, not moved. If the exchange fails, nothing is copied. | false | boolean | |
Whether moveAfterRead removes the value of the prefix option from the start of the key in the destinationBucket. The prefix is removed from the key built from destinationBucketPrefix, the object key and destinationBucketSuffix, so it is removed only when that key starts with it, in practice when destinationBucketPrefix is not set: with the prefix demo/notify/, the object demo/notify/example.txt is copied as example.txt. | false | boolean | |
Whether the consumer closes the object stream when the exchange completes, when includeBody is false and the body is the stream. When false, the route must close the stream, otherwise the HTTP connection that it holds does not go back to the connection pool of the S3 client. Not used when includeBody is true, as the stream is then closed once read. | true | boolean | |
The number of messages after which a batch is complete in streaming upload mode: its object is uploaded, and the next message starts a new object. | 10 | int | |
The size in bytes after which a batch is complete in streaming upload mode: when the buffered data reaches it, the object is uploaded and the next data starts a new object, so the data of a large message can be split between two objects. | 1000000 | int | |
The number of bytes that the producer reads from the message body at a time in streaming upload mode, when multiPartUpload is false (with multiPartUpload, it reads up to partSize bytes). The batchSize is checked after each read. | 1000000 | int | |
Whether to delete the local file after it is uploaded, when the message body is a java.io.File (for example from the file component). Bodies of other types are not affected. Not used in streaming upload mode. | false | boolean | |
The key of the object for the producer operations, used when the CamelAwsS3Key header is not set. It can be a Simple expression, such as $\{header.name}, evaluated for each message. In streaming upload mode it is required, and the uploaded objects are named from it by the namingStrategy: the header and Simple expressions are not used there. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether the producer uploads a body of at least partSize bytes with a multipart upload (CreateMultipartUpload, UploadPart for each part of partSize bytes, then CompleteMultipartUpload). A smaller body is uploaded with a single PutObject. If a part fails, the multipart upload is aborted. In streaming upload mode, the parts are uploaded as the data of a batch is buffered, instead of the whole batch when it is complete. | false | boolean | |
How the objects of the batches are named from keyName in streaming upload mode: progressive adds a counter before the extension (the first object is keyName itself, then name-1.ext, name-2.ext and so on), random adds a random UUID, and timestamp adds the time the upload started, in milliseconds. Not used with timestampGroupingEnabled. Enum values:
| progressive | AWSS3NamingStrategyEnum | |
The operation that the producer performs. The CamelAwsS3Operation header replaces this option. When neither is set, the producer uploads the message body (PutObject, or a multipart upload with multiPartUpload). In streaming upload mode, the producer only uploads and does not use it. Enum values:
| AWS2S3Operations | ||
The size in bytes of each part of a multipart upload, used when multiPartUpload is true. A body smaller than it is uploaded with a single PutObject. S3 requires each part except the last to be at least 5 MiB (5242880 bytes), and accepts at most 10,000 parts and 5 GiB per part. In streaming upload mode, it must also fit in an int. | 26214400 | long | |
Where the progressive namingStrategy starts counting when the producer starts in streaming upload mode: override starts again from keyName, so the new objects replace the objects written before; lastPart finds the most recently modified object whose key starts with keyName (without its extension) and continues after its number. Only used with the progressive namingStrategy. Enum values:
| override | AWSS3RestartingPolicyEnum | |
The storage class of the uploaded objects, a value of the S3 StorageClass such as STANDARD_IA, INTELLIGENT_TIERING or GLACIER. The CamelAwsS3StorageClass header replaces it. It applies to PutObject and multipart uploads, also in streaming upload mode, not to copyObject. | String | ||
Whether the producer uploads the messages in streaming upload mode: it buffers the data of the messages and writes it to objects with multipart uploads, one object for each batch. A batch is complete at batchMessageNumber messages or batchSize bytes, when streamingUploadTimeout runs, or when the producer stops. The objects are named from keyName by the namingStrategy. In this mode the operation option and the headers that name the key or the bucket are not used. | false | boolean | |
The interval in milliseconds at which the producer completes the open uploads in streaming upload mode, whatever their number of messages or size, so that buffered data does not wait for batchMessageNumber or batchSize. It is a fixed interval, not counted from the last message. 0 turns it off. | long | ||
Whether in streaming upload mode the producer writes the messages to one object for each time window of timestampWindowSizeMillis, by the timestamp in the timestampHeaderName header, instead of naming the objects by the namingStrategy. The objects are named from keyName and the window in UTC, for example name_20240101_0800_0800-0805.txt. Only used in streaming upload mode. | false | boolean | |
The name of the header with the timestamp of each message for timestampGroupingEnabled: a Long or a String of milliseconds since the epoch, or a java.util.Date. A message without a valid timestamp goes to the window of the current time. | CamelMessageTimestamp | String | |
The length in milliseconds of the time windows of timestampGroupingEnabled. The windows start at multiples of it since the epoch: 300000 (5 minutes) gives the windows 08:00-08:05, 08:05-08:10 and so on. | 300000 | long | |
The AWS KMS key (key ID, key ARN or alias) that encrypts the uploaded objects when useAwsKMS is true. | String | ||
Whether an upload stores the object only if no object with its key exists in the bucket yet: the producer sends If-None-Match: * with PutObject and with CompleteMultipartUpload, and S3 rejects the upload with the status 412 (Precondition Failed) when the key exists. Not used by copyObject, nor in streaming upload mode. | false | boolean | |
Whether to encrypt the uploaded objects with SSE-KMS (server-side encryption with AWS KMS keys), with the KMS key of the awsKMSKeyId option. It applies to PutObject, multipart uploads (also in streaming upload mode) and the copy of copyObject. Set awsKMSKeyId too: without it, PutObject and copyObject do not ask for SSE-KMS, while a multipart upload uses the AWS managed key aws/s3. | false | boolean | |
Whether to encrypt the uploaded objects with SSE-S3 (server-side encryption with Amazon S3 managed keys, AES256). It applies to PutObject, multipart uploads (also in streaming upload mode) and the copy of copyObject. | false | boolean | |
Autowired To use a custom software.amazon.awssdk.services.s3.S3Client, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override, forcePathStyle and trustAllCertificates options are not used for the client. The endpoint does not close a client that is set or autowired. | S3Client | ||
Autowired To use a custom software.amazon.awssdk.services.s3.presigner.S3Presigner for the createDownloadLink and createUploadLink operations, which is autowired when the registry has a single one. When it is not set, the producer creates a presigner for each link from the credentials, region, forcePathStyle and uriEndpointOverride options, and closes it after use. | S3Presigner | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
The host name of the proxy that the S3 client uses. The client uses a proxy only when the proxyPort option is set too. | String | ||
The port of the proxy that the S3 client uses. The client uses a proxy only when the proxyHost option is set too. | Integer | ||
The protocol of the proxy that the S3 client uses. It is used only when the proxyHost and proxyPort options are both set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless amazonS3Client is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless amazonS3Client is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the S3 client accepts any TLS certificate of the server without checking it. It applies whether or not the endpoint is overridden. Use it only for tests, for example with a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Endpoint Options
The AWS S3 Storage Service endpoint is configured using URI syntax:
aws2-s3://bucketNameOrArn
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The name of the bucket, or its ARN such as arn:aws:s3:::mybucket, of which the part after the last colon is used as the name. The producer operations evaluate a Simple expression in it, such as $\{header.bucket}, for each message, and the CamelAwsS3OverrideBucketName header replaces it. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Whether to create the bucket (CreateBucket) when the endpoint starts and HeadBucket answers that it does not exist. With moveAfterRead, the consumer also creates the destinationBucket. When false, a missing bucket is not created, and the operations on it fail. Not used when fileName is set. | false | boolean | |
The delimiter of the ListObjectsV2 request of the consumer and of the listObjects operation, where the CamelAwsS3Delimiter header replaces it. S3 groups the keys that contain the delimiter after the prefix into common prefixes and does not return them as objects: for example the delimiter / with the prefix logs/ lists only the objects directly under logs/, not those under logs/2024/. | String | ||
Whether the S3 client uses path-style requests, with the bucket name in the path of the URL (https://s3.eu-west-1.amazonaws.com/mybucket/key), instead of virtual-hosted-style requests, with the bucket name in the host name (https://mybucket.s3.eu-west-1.amazonaws.com/key). Many S3-compatible stores used with uriEndpointOverride need it. | false | boolean | |
Whether to get only the metadata of the objects, without their content: the consumer and the getObject operation send a HeadObject request instead of GetObject, set the same headers, and set no body (the consumer) or keep the body (getObject). The headBucket operation then keeps the body too. It takes precedence over includeBody. | false | boolean | |
Whether the S3 client sends the requests to the URI of the uriEndpointOverride option instead of the S3 endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
Whether the producer operations take their request from the message body: the request of the AWS SDK for the operation, such as a GetObjectRequest for getObject or a ListObjectsV2Request for listObjects. The upload (no operation), listBuckets, headBucket, headObject, createDownloadLink and createUploadLink do not use it. | false | boolean | |
A bucket policy, as JSON, that the endpoint sets on the bucket with PutBucketPolicy when it starts. It is set only when the bucket does not exist yet, after autoCreateBucket created it: the policy of an existing bucket is not changed. | String | ||
Only the objects whose key begins with this prefix are listed: by the consumer (the Prefix of its ListObjectsV2 request) and by the listObjects operation, where the CamelAwsS3Prefix header replaces it. The removePrefixOnMove option also uses it. | String | ||
The ID of the AWS region of the S3 client, in lower case, for example eu-west-1 (the value of Region.EU_WEST_1.id()). autoCreateBucket creates the bucket in this region. If not set, the AWS SDK resolves the region itself, for example from the AWS_REGION environment variable. Enum values:
| String | ||
The URI that the S3 client sends the requests to, for example http://localhost:9000 for a local S3-compatible store. The client uses it only when overrideEndpoint is true, while the presigner of createDownloadLink and createUploadLink uses it whenever it is set. | String | ||
The encryption algorithm of SSE-C, used when useCustomerKey is true. S3 supports only AES256. | String | ||
The customer-provided key of SSE-C, used when useCustomerKey is true: the 256-bit key itself, base64-encoded, not an ID. In an endpoint URI, use RAW() around it, as a base64 value can contain + and / characters. | String | ||
The base64-encoded 128-bit MD5 digest of the customer-provided key of customerKeyId, which S3 uses to check that it received the key without error. Used when useCustomerKey is true. | String | ||
Whether to use server-side encryption with a customer-provided key (SSE-C), the key of the customerKeyId, customerKeyMD5 and customerAlgorithm options. The key is sent with the get of each consumed object, and by the producer with PutObject, multipart uploads (also in streaming upload mode), getObject, getObjectRange and copyObject (for the source and the copy). S3 needs the same key to read an object stored with it. | false | boolean | |
Whether to delete each consumed object from the bucket after its exchange completes successfully. If the exchange fails, the object is not deleted, and a later poll consumes it again. When false, the polls consume the same objects again and again: use the Idempotent Consumer EIP to filter out the duplicates, for example on the CamelAwsS3Key header. With moveAfterRead, the object is deleted after it is copied. | true | boolean | |
The bucket that moveAfterRead copies the consumed objects to. The consumer checks at startup that it exists, and creates it when autoCreateBucket is true. | String | ||
A prefix that moveAfterRead puts before the key of the object in the destinationBucket, for example archive/. It can be a Simple expression, evaluated with the exchange of the object. | String | ||
A suffix that moveAfterRead appends to the key of the object in the destinationBucket, after its extension, for example .processed. It can be a Simple expression, evaluated with the exchange of the object. | String | ||
The key of a done file: when it is set, a poll consumes objects only when an object with this key exists in the bucket (checked with HeadObject at the start of each poll). It is one fixed key, not a pattern. The done file is listed and consumed like the other objects, unless the prefix option leaves it out. | String | ||
The key of the one object to consume. When it is set, each poll gets this object instead of listing the bucket, and the endpoint does not check at startup that the bucket exists (so autoCreateBucket and policy are not applied). | String | ||
Whether the consumer reads the content of each object into the message body as a byte array, and then closes the object stream. When false, the body is the object stream itself (a ResponseInputStream of the AWS SDK), which holds an HTTP connection of the S3 client until it is closed: autocloseBody closes it when the exchange completes, otherwise the route must close it. ignoreBody takes precedence over this option. | true | boolean | |
Whether the consumer consumes the folder objects, the objects whose Content-Type is application/x-directory (such as the S3 console creates for a folder). When false, they are skipped and stay in the bucket. | true | boolean | |
Deprecated Set the maxConnections parameter in the S3 client configuration. This option is deprecated and has no effect: the S3 client that Camel creates uses the connection pool of the AWS SDK, of 50 connections by default. The consumer gets each object right before routing its exchange, so it does not hold a connection for every object of a poll. To use another pool size, set the amazonS3Client option to an S3 client built with an HTTP client of that size. | 60 | int | |
The maximum number of objects that one poll lists and consumes: the MaxKeys of the ListObjectsV2 request. S3 returns at most 1,000 keys for each request, so 0, a negative number (no limit) or a larger value lists up to 1,000 objects. The next poll continues the listing where the previous one stopped. | 10 | int | |
Whether to copy each consumed object to the destinationBucket after its exchange completes successfully, with the key destinationBucketPrefix + key + destinationBucketSuffix. The object is removed from the bucket only by deleteAfterRead (true by default): with deleteAfterRead false, it is copied, not moved. If the exchange fails, nothing is copied. | false | boolean | |
Whether moveAfterRead removes the value of the prefix option from the start of the key in the destinationBucket. The prefix is removed from the key built from destinationBucketPrefix, the object key and destinationBucketSuffix, so it is removed only when that key starts with it, in practice when destinationBucketPrefix is not set: with the prefix demo/notify/, the object demo/notify/example.txt is copied as example.txt. | false | boolean | |
If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean | |
Whether the consumer closes the object stream when the exchange completes, when includeBody is false and the body is the stream. When false, the route must close the stream, otherwise the HTTP connection that it holds does not go back to the connection pool of the S3 client. Not used when includeBody is true, as the stream is then closed once read. | true | boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
The org.apache.camel.spi.IdempotentRepository of the keys of the objects that are being consumed, so that a poll skips an object that the exchange of an earlier poll is still processing. A key is removed when its exchange completes or fails. By default an in-memory repository of up to 10000 keys. | IdempotentRepository | ||
A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. | PollingConsumerPollStrategy | ||
The number of messages after which a batch is complete in streaming upload mode: its object is uploaded, and the next message starts a new object. | 10 | int | |
The size in bytes after which a batch is complete in streaming upload mode: when the buffered data reaches it, the object is uploaded and the next data starts a new object, so the data of a large message can be split between two objects. | 1000000 | int | |
The number of bytes that the producer reads from the message body at a time in streaming upload mode, when multiPartUpload is false (with multiPartUpload, it reads up to partSize bytes). The batchSize is checked after each read. | 1000000 | int | |
Whether to delete the local file after it is uploaded, when the message body is a java.io.File (for example from the file component). Bodies of other types are not affected. Not used in streaming upload mode. | false | boolean | |
The key of the object for the producer operations, used when the CamelAwsS3Key header is not set. It can be a Simple expression, such as $\{header.name}, evaluated for each message. In streaming upload mode it is required, and the uploaded objects are named from it by the namingStrategy: the header and Simple expressions are not used there. | String | ||
Whether the producer uploads a body of at least partSize bytes with a multipart upload (CreateMultipartUpload, UploadPart for each part of partSize bytes, then CompleteMultipartUpload). A smaller body is uploaded with a single PutObject. If a part fails, the multipart upload is aborted. In streaming upload mode, the parts are uploaded as the data of a batch is buffered, instead of the whole batch when it is complete. | false | boolean | |
How the objects of the batches are named from keyName in streaming upload mode: progressive adds a counter before the extension (the first object is keyName itself, then name-1.ext, name-2.ext and so on), random adds a random UUID, and timestamp adds the time the upload started, in milliseconds. Not used with timestampGroupingEnabled. Enum values:
| progressive | AWSS3NamingStrategyEnum | |
The operation that the producer performs. The CamelAwsS3Operation header replaces this option. When neither is set, the producer uploads the message body (PutObject, or a multipart upload with multiPartUpload). In streaming upload mode, the producer only uploads and does not use it. Enum values:
| AWS2S3Operations | ||
The size in bytes of each part of a multipart upload, used when multiPartUpload is true. A body smaller than it is uploaded with a single PutObject. S3 requires each part except the last to be at least 5 MiB (5242880 bytes), and accepts at most 10,000 parts and 5 GiB per part. In streaming upload mode, it must also fit in an int. | 26214400 | long | |
Where the progressive namingStrategy starts counting when the producer starts in streaming upload mode: override starts again from keyName, so the new objects replace the objects written before; lastPart finds the most recently modified object whose key starts with keyName (without its extension) and continues after its number. Only used with the progressive namingStrategy. Enum values:
| override | AWSS3RestartingPolicyEnum | |
The storage class of the uploaded objects, a value of the S3 StorageClass such as STANDARD_IA, INTELLIGENT_TIERING or GLACIER. The CamelAwsS3StorageClass header replaces it. It applies to PutObject and multipart uploads, also in streaming upload mode, not to copyObject. | String | ||
Whether the producer uploads the messages in streaming upload mode: it buffers the data of the messages and writes it to objects with multipart uploads, one object for each batch. A batch is complete at batchMessageNumber messages or batchSize bytes, when streamingUploadTimeout runs, or when the producer stops. The objects are named from keyName by the namingStrategy. In this mode the operation option and the headers that name the key or the bucket are not used. | false | boolean | |
The interval in milliseconds at which the producer completes the open uploads in streaming upload mode, whatever their number of messages or size, so that buffered data does not wait for batchMessageNumber or batchSize. It is a fixed interval, not counted from the last message. 0 turns it off. | long | ||
Whether in streaming upload mode the producer writes the messages to one object for each time window of timestampWindowSizeMillis, by the timestamp in the timestampHeaderName header, instead of naming the objects by the namingStrategy. The objects are named from keyName and the window in UTC, for example name_20240101_0800_0800-0805.txt. Only used in streaming upload mode. | false | boolean | |
The name of the header with the timestamp of each message for timestampGroupingEnabled: a Long or a String of milliseconds since the epoch, or a java.util.Date. A message without a valid timestamp goes to the window of the current time. | CamelMessageTimestamp | String | |
The length in milliseconds of the time windows of timestampGroupingEnabled. The windows start at multiples of it since the epoch: 300000 (5 minutes) gives the windows 08:00-08:05, 08:05-08:10 and so on. | 300000 | long | |
The AWS KMS key (key ID, key ARN or alias) that encrypts the uploaded objects when useAwsKMS is true. | String | ||
Whether an upload stores the object only if no object with its key exists in the bucket yet: the producer sends If-None-Match: * with PutObject and with CompleteMultipartUpload, and S3 rejects the upload with the status 412 (Precondition Failed) when the key exists. Not used by copyObject, nor in streaming upload mode. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether to encrypt the uploaded objects with SSE-KMS (server-side encryption with AWS KMS keys), with the KMS key of the awsKMSKeyId option. It applies to PutObject, multipart uploads (also in streaming upload mode) and the copy of copyObject. Set awsKMSKeyId too: without it, PutObject and copyObject do not ask for SSE-KMS, while a multipart upload uses the AWS managed key aws/s3. | false | boolean | |
Whether to encrypt the uploaded objects with SSE-S3 (server-side encryption with Amazon S3 managed keys, AES256). It applies to PutObject, multipart uploads (also in streaming upload mode) and the copy of copyObject. | false | boolean | |
Autowired To use a custom software.amazon.awssdk.services.s3.S3Client, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override, forcePathStyle and trustAllCertificates options are not used for the client. The endpoint does not close a client that is set or autowired. | S3Client | ||
Autowired To use a custom software.amazon.awssdk.services.s3.presigner.S3Presigner for the createDownloadLink and createUploadLink operations, which is autowired when the registry has a single one. When it is not set, the producer creates a presigner for each link from the credentials, region, forcePathStyle and uriEndpointOverride options, and closes it after use. | S3Presigner | ||
The host name of the proxy that the S3 client uses. The client uses a proxy only when the proxyPort option is set too. | String | ||
The port of the proxy that the S3 client uses. The client uses a proxy only when the proxyHost option is set too. | Integer | ||
The protocol of the proxy that the S3 client uses. It is used only when the proxyHost and proxyPort options are both set. Enum values:
| HTTPS | Protocol | |
The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | int | ||
The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | int | ||
To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. | int | ||
Milliseconds before the next poll. | 500 | long | |
If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean | |
How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off. | 0 | long | |
Milliseconds before the first poll starts. | 1000 | long | |
Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long | |
The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. Enum values:
| TRACE | LoggingLevel | |
Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. | ScheduledExecutorService | ||
To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler. | none | Object | |
To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler. | Map | ||
Whether the scheduler should be auto started. | true | boolean | |
Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit | |
Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless amazonS3Client is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless amazonS3Client is set or useDefaultCredentialsProvider, useProfileCredentialsProvider or useSessionCredentials is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the S3 client accepts any TLS certificate of the server without checking it. It applies whether or not the endpoint is overridden. Use it only for tests, for example with a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Message Headers
The AWS S3 Storage Service component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | The name of the bucket of the consumed object. The producer does not read this header: use CamelAwsS3OverrideBucketName to use another bucket than the one of the endpoint. | String | |
CamelAwsS3ProducedBucketName (producer) Constant: | The bucket that the producer used for the operation (from the CamelAwsS3OverrideBucketName header or the bucket of the endpoint), set after the operation. | String | |
CamelAwsS3BucketDestinationName (producer) Constant: | The bucket that the copyObject operation copies the object to. Required by copyObject. | String | |
CamelAwsS3BucketExists (common) Constant: | Whether the bucket exists, set by the headBucket operation: false when S3 answers that there is no such bucket. | boolean | |
CamelAwsS3ContentControl (common) Constant: | The optional Cache-Control HTTP header which allows the user to specify caching behavior along the HTTP request/reply chain. | String | |
CamelAwsS3ContentDisposition (common) Constant: | The optional Content-Disposition HTTP header, which specifies presentational information such as the recommended filename for the object to be saved as. | String | |
CamelAwsS3ContentEncoding (common) Constant: | The optional Content-Encoding HTTP header specifying what content encodings have been applied to the object and what decoding mechanisms must be applied in order to obtain the media-type referenced by the Content-Type field. | String | |
CamelAwsS3ContentLength (common) Constant: | The size of the object in bytes (Content-Length). The consumer and the getObject operation set it. An upload uses it as the length of a body whose length is not known without reading it, such as a stream. | Long | |
| Constant: | The base64-encoded 128-bit MD5 digest of the content to upload (Content-MD5, RFC 1864), which S3 uses to check that it received the content without error. Only a single PutObject upload sends it, not a multipart upload. | String | |
CamelAwsS3ContentType (common) Constant: | The Content-Type HTTP header, which indicates the type of content stored in the associated object. The value of this header is a standard MIME type. | String | |
| Constant: | The entity tag (ETag) of the object: of the consumed or got object, or of the object that an upload stored. For an object uploaded with a single PutObject and not encrypted with SSE-KMS or SSE-C, it is the hex MD5 digest of its content; for a multipart upload it is not. | String | |
| Constant: | The key of the object: of the consumed object, and for the producer the key that the operation uses, instead of the keyName option. The producer uses the value of the header as it is: Simple expressions are only evaluated in the keyName option. Not used in streaming upload mode. | String | |
CamelAwsS3ProducedKey (producer) Constant: | The key that the producer used for the operation (from the CamelAwsS3Key header or the keyName option), set after the operation. | String | |
CamelAwsS3DestinationKey (producer) Constant: | The key of the copy that the copyObject operation creates in the destination bucket. Required by copyObject. | String | |
CamelAwsS3LastModified (common) Constant: | The value of the Last-Modified header, indicating the date and time at which Amazon S3 last recorded a modification to the associated object. | Date | |
CamelAwsS3StorageClass (common) Constant: | The storage class of the object, set by the consumer and the getObject operation. An upload uses it instead of the storageClass option. | String | |
| Constant: | (producer) The optional version ID of the newly uploaded object. (consumer) The version ID of the associated Amazon S3 object if available. Version IDs are only assigned to objects when an object is uploaded to an Amazon S3 bucket that has object versioning enabled. | String | |
CamelAwsS3CannedAcl (producer) Constant: | The canned ACL to apply to the uploaded object, and the one that the putObjectAcl operation sets (required there). The value is the name of a constant of software.amazon.awssdk.services.s3.model.ObjectCannedACL, such as PRIVATE or BUCKET_OWNER_FULL_CONTROL. | String | |
| Constant: | A canned ACL, as a BucketCannedACL, whose value (such as private or public-read) is applied to the uploaded object. It replaces CamelAwsS3CannedAcl when both are set. Enum values:
| BucketCannedACL | |
CamelAwsS3GrantFullControl (producer) Constant: | Gives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object. The value is a grantee expression: id= followed by the canonical user ID, emailAddress= followed by the email address, or uri= followed by the URI of the group. | String | |
CamelAwsS3GrantRead (producer) Constant: | Allows the grantee to read the object data and its metadata. The value is a grantee expression: id= followed by the canonical user ID, emailAddress= followed by the email address, or uri= followed by the URI of the group. | String | |
CamelAwsS3GrantReadACP (producer) Constant: | Allows the grantee to read the object ACL. The value is a grantee expression: id= followed by the canonical user ID, emailAddress= followed by the email address, or uri= followed by the URI of the group. | String | |
CamelAwsS3GrantWriteACP (producer) Constant: | Allows the grantee to write the ACL for the object. The value is a grantee expression: id= followed by the canonical user ID, emailAddress= followed by the email address, or uri= followed by the URI of the group. | String | |
| Constant: | The operation that the producer performs, one of the values of the operation option, which this header replaces. | String | |
CamelAwsS3ServerSideEncryption (common) Constant: | The server-side encryption of the object as S3 returns it, such as AES256 or aws:kms, set by the consumer and the getObject operation. The producer does not read it: use the useSSES3 or useAwsKMS option. | String | |
CamelAwsS3ExpirationTime (consumer) Constant: | When a lifecycle rule of the bucket expires the object, the expiry date and the ID of the rule (the x-amz-expiration header of the response). | String | |
CamelAwsS3ReplicationStatus (consumer) Constant: | Amazon S3 can return this if your request involves a bucket that is either a source or destination in a replication rule. Enum values:
| ReplicationStatus | |
CamelAwsS3RangeStart (producer) Constant: | The position of the first byte to get with the getObjectRange operation, counted from 0. Required by getObjectRange. | String | |
| Constant: | The position of the last byte to get with the getObjectRange operation, included in the range. Required by getObjectRange. | String | |
CamelAwsS3DowloadLinkExpirationTime (producer) Constant: | How long the link of the createDownloadLink operation is valid, in milliseconds. The default is one hour. A presigned URL is valid for at most 7 days. | Long | |
CamelAwsS3DownloadLinkBrowserCompatible (producer) Constant: | Whether the link of the createDownloadLink operation works from a browser, without other headers or payload than the URL. Set by createDownloadLink. | boolean | |
CamelAwsS3DownloadLinkHttpRequestHeaders (producer) Constant: | The HTTP headers that a request to the link of createDownloadLink must send, set when the link is not browser compatible. | Map | |
CamelAwsS3DownloadLinkSignedPayload (producer) Constant: | The payload that a request to the link of createDownloadLink must send, set when the link is not browser compatible and has a signed payload. | String | |
| Constant: | The user-defined metadata of the object (the x-amz-meta-* headers), as a map. An upload stores it with the object (not in streaming upload mode), and the consumer and the getObject operation set it. More details about metadata here. | Map | |
CamelMessageTimestamp (common) Constant: | The timestamp of the message: the last modified time of the object. | long | |
CamelHttpResponseCode (producer) Constant: | Set by the producer after most operations, and after a streaming upload: the HTTP status code of the response of S3, as an Integer. | Integer | |
| Constant: | The prefix of the listObjects operation: only the objects whose key begins with it are listed. It replaces the prefix option. | ||
| Constant: | The delimiter of the listObjects operation, which replaces the delimiter option: the keys that contain it after the prefix are grouped into common prefixes and not listed as objects. | String | |
CamelAwsS3IfMatchCondition (common) Constant: | The getObject and copyObject operations get or copy the object only if its entity tag (ETag) is the one of this header; otherwise S3 answers with the status 412 (Precondition Failed). | String | |
CamelAwsS3IfModifiedSinceCondition (common) Constant: | The getObject and copyObject operations get or copy the object only if it was modified after this time, a java.time.Instant; otherwise S3 answers with the status 304 (Not Modified) for getObject, and 412 (Precondition Failed) for copyObject. | String | |
CamelAwsS3IfNoneMatchCondition (common) Constant: | The getObject and copyObject operations get or copy the object only if its entity tag (ETag) is not the one of this header; otherwise S3 answers with the status 304 (Not Modified) for getObject, and 412 (Precondition Failed) for copyObject. | String | |
CamelAwsS3IfUnmodifiedSinceCondition (common) Constant: | The getObject and copyObject operations get or copy the object only if it was not modified after this time, a java.time.Instant; otherwise S3 answers with the status 412 (Precondition Failed). | String | |
CamelAwsS3OverrideBucketName (common) Constant: | The bucket that the producer operation uses, instead of the bucket of the endpoint. The producer uses the value of the header as it is: Simple expressions are only evaluated in the bucket of the endpoint. Not used in streaming upload mode. | String | |
CamelAwsS3KeysToDelete (producer) Constant: | The keys of the objects that the deleteObjects operation deletes. Required by deleteObjects. | List | |
CamelAwsS3RestoreDays (producer) Constant: | The number of days that the copy of the object that the restoreObject operation restores stays available. The default is 1. | Integer | |
CamelAwsS3RestoreTier (producer) Constant: | The retrieval tier of the restoreObject operation: Standard (the default), Bulk or Expedited. | String | |
CamelAwsS3ObjectTags (producer) Constant: | The tags, as a map of key and value, that the putObjectTagging operation sets on the object, replacing its tags. Required by putObjectTagging. | Map | |
CamelAwsS3BucketTags (producer) Constant: | The tags, as a map of key and value, that the putBucketTagging operation sets on the bucket, replacing its tags. Required by putBucketTagging. | Map | |
CamelAwsS3BucketPolicy (producer) Constant: | The bucket policy, as JSON, that the putBucketPolicy operation sets. Required by putBucketPolicy. | String | |
CamelAwsS3VersioningStatus (producer) Constant: | The versioning status that the putBucketVersioning operation sets: Enabled or Suspended. Required by putBucketVersioning. | String | |
CamelAwsS3MfaDelete (producer) Constant: | The MFA delete status that the putBucketVersioning operation sets: Enabled or Disabled. | String | |
CamelAwsS3UploadLinkExpirationTime (producer) Constant: | How long the link of the createUploadLink operation is valid, in milliseconds. The default is one hour. A presigned URL is valid for at most 7 days. | Long | |
CamelAwsS3UploadLinkBrowserCompatible (producer) Constant: | Whether the link of the createUploadLink operation works from a browser, without other headers or payload than the URL. Set by createUploadLink. | boolean | |
CamelAwsS3UploadLinkHttpRequestHeaders (producer) Constant: | The HTTP headers that a request to the link of createUploadLink must send, set when the link is not browser compatible. | Map | |
CamelAwsS3UploadLinkSignedPayload (producer) Constant: | The payload that a request to the link of createUploadLink must send, set when the link is not browser compatible and has a signed payload. | String |
Message Body
The message body at each side of the AWS S3 Storage Service component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| The content of the object as a byte array, one message per object, with its key and metadata in headers. With includeBody=false the stream of the object, and with ignoreBody=true no body.
|
Producer input |
| The content to upload, when no operation is set: text, bytes, a stream or a file. A Map or a List fails: marshal it first. The operations take their input from headers, or with pojoRequest=true from the request of the AWS SDK in the body, such as a GetObjectRequest. Not known when |
Producer output |
| Unchanged after an upload and a copyObject, with the ETag in a header. By the operation: the stream of the object for getObject and getObjectRange, a List for the lists and the tagging gets, the URL as text for the links, the policy JSON for getBucketPolicy, true for deleteObject, and the response of the AWS SDK for the others. getObject with ignoreBody=true, headBucket for a bucket that does not exist and streamingUploadMode keep the body.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Required S3 component options
You have to provide the amazonS3Client in the Registry or your accessKey and secretKey to access the Amazon’s S3.
Usage
Batch Consumer
This component implements the Batch Consumer.
This allows you, for instance, to know how many messages exist in this batch and for instance, let the Aggregator aggregate this number of messages (see the note below when objects of the poll can be skipped).
The consumer lists the objects of a poll, and gets each of them right before its exchange is routed, so that only the objects of the exchanges in flight are in memory, or hold a connection of the HTTP client (with includeBody=false). With ignoreBody=true it sends a HEAD request instead, which returns the metadata of the object without its content.
The batch properties count the listed objects. If an object is skipped when it is got (it was deleted after the listing, for example by another consumer; it cannot be got; or it is a folder and includeFolders is false), CamelBatchSize is higher than the number of exchanges routed for the batch, and possibly no exchange has CamelBatchComplete set to true. An aggregator with completionFromBatchConsumer then does not complete the group of the poll: the group waits for the exchanges of the next poll, and is completed with some of them. When objects can be skipped, for example with includeFolders=false and folders in the bucket, or with several consumers of the same bucket (such as several pods of the same application), use completionTimeout instead of completionFromBatchConsumer (not both): a timeout longer than the time between two exchanges of a poll, and shorter than the delay of the consumer minus the completionTimeoutCheckerInterval (1 second by default), completes one group per poll. |
S3 Producer operations
Camel-AWS2-S3 component provides the following operation on the producer side:
-
copyObject
-
deleteObject
-
deleteObjects
-
listBuckets
-
deleteBucket
-
listObjects
-
getObject (this will return the content of the object as a stream)
-
getObjectRange (this will return the range of the content as a stream)
-
createDownloadLink
-
createUploadLink
-
headBucket
-
headObject
-
restoreObject
-
getObjectTagging
-
putObjectTagging
-
deleteObjectTagging
-
getObjectAcl
-
putObjectAcl
-
createBucket
-
getBucketTagging
-
putBucketTagging
-
deleteBucketTagging
-
getBucketVersioning
-
putBucketVersioning
-
getBucketPolicy
-
putBucketPolicy
-
deleteBucketPolicy
If you don’t specify an operation, explicitly the producer will do:
-
a single file upload
-
a multipart upload if multiPartUpload option is enabled
Examples
For example, to read file hello.txt from bucket helloBucket, use the following snippet:
-
Java
-
XML
-
YAML
from("aws2-s3://helloBucket?accessKey=yourAccessKey&secretKey=yourSecretKey&prefix=hello.txt")
.to("file:/var/downloaded"); <route>
<from uri="aws2-s3://helloBucket?accessKey=yourAccessKey&secretKey=yourSecretKey&prefix=hello.txt"/>
<to uri="file:/var/downloaded"/>
</route> - route:
from:
uri: aws2-s3://helloBucket
parameters:
accessKey: yourAccessKey
secretKey: yourSecretKey
prefix: hello.txt
steps:
- to:
uri: file:/var/downloaded Advanced AmazonS3 configuration
If your Camel Application is running behind a firewall or if you need to have more control over the S3Client instance configuration, you can create your own instance and refer to it in your Camel aws2-s3 component configuration:
-
Java
-
XML
-
YAML
from("aws2-s3://MyBucket?amazonS3Client=#client&delay=5000&maxMessagesPerPoll=5")
.to("mock:result"); <route>
<from uri="aws2-s3://MyBucket?amazonS3Client=#client&delay=5000&maxMessagesPerPoll=5"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: aws2-s3://MyBucket
parameters:
amazonS3Client: "#client"
delay: 5000
maxMessagesPerPoll: 5
steps:
- to:
uri: mock:result Use KMS with the S3 component
To use AWS KMS to encrypt/decrypt data by using AWS infrastructure, you can use the options introduced in 2.21.x like in the following example
-
Java
-
XML
-
YAML
from("file:tmp/test?fileName=test.txt")
.setHeader("CamelAwsS3Key", constant("testFile"))
.to("aws2-s3://mybucket?amazonS3Client=#client&useAwsKMS=true&awsKMSKeyId=3f0637ad-296a-3dfe-a796-e60654fb128c"); <route>
<from uri="file:tmp/test?fileName=test.txt"/>
<setHeader name="CamelAwsS3Key">
<constant>testFile</constant>
</setHeader>
<to uri="aws2-s3://mybucket?amazonS3Client=#client&useAwsKMS=true&awsKMSKeyId=3f0637ad-296a-3dfe-a796-e60654fb128c"/>
</route> - route:
from:
uri: file:tmp/test
parameters:
fileName: test.txt
steps:
- setHeader:
name: CamelAwsS3Key
constant: testFile
- to:
uri: aws2-s3://mybucket
parameters:
amazonS3Client: "#client"
useAwsKMS: true
awsKMSKeyId: "3f0637ad-296a-3dfe-a796-e60654fb128c" The Java example uses the string value "CamelAwsS3Key" directly. You can also use the Java constant AWS2S3Constants.KEY. |
In this way, you’ll ask S3 to use the KMS key 3f0637ad-296a-3dfe-a796-e60654fb128c, to encrypt the file test.txt. When you ask to download this file, the decryption will be done directly before the download.
Static credentials, Default Credential Provider and Profile Credentials Provider
You have the possibility of avoiding the usage of explicit static credentials by specifying the useDefaultCredentialsProvider option and set it to true.
The order of evaluation for Default Credentials Provider is the following:
-
Java system properties -
aws.accessKeyIdandaws.secretKey. -
Environment variables -
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. -
Web Identity Token from AWS STS.
-
The shared credentials and config files.
-
Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIis set. -
Amazon EC2 Instance profile credentials.
You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of static, default and profile credentials could be used at the same time.
For more information about this you can look at AWS credentials documentation
Bucket Auto-creation
With the option autoCreateBucket users are able to avoid the auto-creation of an S3 Bucket in case it doesn’t exist. The default for this option is false. If set to false, any operation on a not-existent bucket in AWS won’t be successful and an error will be returned.
Moving stuff between a bucket and another bucket
Some users like to consume stuff from a bucket and move the content in a different one without using the copyObject feature of this component. The producer does not read the CamelAwsS3BucketName header that the consumer sets: it writes to the bucket of its own endpoint (or to the bucket of the CamelAwsS3OverrideBucketName header). It takes the key from the CamelAwsS3Key header, so the object keeps its key in the other bucket.
Using the customer key as encryption
We introduced also the customer key support (an alternative of using KMS). The following code shows an example.
String key = UUID.randomUUID().toString();
byte[] secretKey = generateSecretKey();
String b64Key = Base64.getEncoder().encodeToString(secretKey);
String b64KeyMd5 = Md5Utils.md5AsBase64(secretKey);
String awsEndpoint = "aws2-s3://mycamel?autoCreateBucket=false&useCustomerKey=true&customerKeyId=RAW(" + b64Key + ")&customerKeyMD5=RAW(" + b64KeyMd5 + ")&customerAlgorithm=" + AES256.name();
from("direct:putObject")
.setHeader("CamelAwsS3Key", constant("test.txt"))
.setBody(constant("Test"))
.to(awsEndpoint); Using a POJO as body
Sometimes building an AWS Request can be complex because of multiple options. We introduce the possibility to use a POJO as the body. In AWS S3 there are multiple operations you can submit, as an example for List objects request, you can do something like:
from("direct:aws2-s3")
.setBody(ListObjectsV2Request.builder().bucket(bucketName).build())
.to("aws2-s3://test?amazonS3Client=#amazonS3Client&operation=listObjects&pojoRequest=true"); In this way, you’ll pass the request directly without the need of passing headers and options specifically related to this operation.
Create S3 client and add component to registry
Sometimes you would want to perform some advanced configuration using AWS2S3Configuration, which also allows to set the S3 client. You can create and set the S3 client in the component configuration as shown in the following example
String awsBucketAccessKey = "your_access_key";
String awsBucketSecretKey = "your_secret_key";
S3Client s3Client = S3Client.builder()
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(awsBucketAccessKey, awsBucketSecretKey)))
.region(Region.US_EAST_1).build();
AWS2S3Configuration configuration = new AWS2S3Configuration();
configuration.setAmazonS3Client(s3Client);
configuration.setAutoDiscoverClient(true);
configuration.setBucketName("s3bucket2020");
configuration.setRegion("us-east-1"); Now you can configure the S3 component (using the configuration object created above) and add it to the registry in the configure method before initialization of routes.
AWS2S3Component s3Component = new AWS2S3Component(getContext());
s3Component.setConfiguration(configuration);
s3Component.setLazyStartProducer(true);
camelContext.addComponent("aws2-s3", s3Component); Now your component will be used for all the operations implemented in camel routes.
Note about using this component for storing and retrieving objects from/to Dell ECS (Elastic Cloud Solutions)
For storing and retrieving objects from/to Dell ECS, both of the forcePathStyle and overrideEndpoint options need to be set to true and using the uriEndpointOverride you need to provide your own ECS endpoint.
String awsBucketAccessKey = "your_access_key";
String awsBucketSecretKey = "your_secret_key";
S3Client s3Client = S3Client.builder()
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create(awsBucketAccessKey, awsBucketSecretKey)))
.region(Region.US_EAST_1).build();
AWS2S3Configuration configuration = new AWS2S3Configuration();
configuration.setForcePathStyle(true);
configuration.setOverrideEndpoint(true);
configuration.setUriEndpointOverride("http://ecs1.emc.com:9020"); For more details see their documentation.
Sub-Pages
For more details on specific features, see:
-
Producer Operations - All producer operation examples with minimum IAM permissions
-
Streaming Upload - Streaming upload mode, naming strategies, and timestamp grouping
-
Consumer Examples - Consumer patterns including prefix filtering, polling strategies, and done files
Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws2-s3</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.