Chapter 16. AWS S3 Source
Receive data from an Amazon S3 Bucket.
The basic authentication method for the S3 service is to specify an access key and a secret key. These parameters are optional because the Kamelet provides a default credentials provider.
If you use the default credentials provider, the S3 client loads the credentials through this provider and doesn’t use the basic authentication method.
Two headers are duplicated with different names for clarity at sink level. CamelAwsS3Key is duplicated into aws.s3.key and CamelAwsS3BucketName is duplicated in aws.s3.bucket.name.
16.1. Authentication methods Copy linkLink copied to clipboard!
In this Kamelet you can avoid using 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 can also use the Profile Credentials Provider, by setting the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of access key/secret key or default credentials provider could be used
For more information, see the AWS credentials documentation
16.2. Usage examples Copy linkLink copied to clipboard!
You could consume the bucket content and directly delete the object once consumed
- route:
from:
uri: "kamelet:aws-s3-source"
parameters:
useDefaultCredentialsProvider: true
region: "eu-west-1"
bucketNameOrArn: "kamelets"
steps:
- to:
uri: "kamelet:log-sink"
This kind of approach ensures that the object is consumed just one time and after the consumption it is deleted from the S3 bucket.
The deleteAfterRead property is true by default.
If you set the property to false you’ll consume the same set of objects multiple times and you’ll have to deal with managing the situation.
The ignoreBody option is set to false by default, but you can enable it. With that option set you’re going to ignore the file payload and just consume the object metadata.
You could also define a prefix parameter. With that set you’re going to consume only files starting with that prefix. As an example you could have:
- route:
from:
uri: "kamelet:aws-s3-source"
parameters:
useDefaultCredentialsProvider: true
region: "eu-west-1"
bucketNameOrArn: "kamelets"
prefix: "foo/"
steps:
- to:
uri: "kamelet:log-sink"
By using the prefix foo/ the files consumed will only come from the folder named foo.
16.3. Configuration Options Copy linkLink copied to clipboard!
The following table summarizes the configuration options available for the aws-s3-source Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
| bucketNameOrArn * | Bucket Name | The S3 Bucket name or Amazon Resource Name (ARN). | string | ||
| region * | AWS Region | The AWS region to access. | string | ||
| accessKey | Access Key | The access key obtained from AWS. | string | ||
| autoCreateBucket | Autocreate Bucket | Specifies to automatically create the S3 bucket. | boolean | False | |
| delay | Delay | The number of milliseconds before the next poll of the selected bucket. | integer | 500 | |
| deleteAfterRead | Auto-delete Objects | Specifies to delete objects after consuming them. | boolean | True | |
| destinationBucket | Destination Bucket | Define the destination bucket where an object must be moved when moveAfterRead is set to true. | string | ||
| destinationBucketPrefix | Destination Bucket Prefix | Define the destination bucket prefix to use when an object must be moved, and moveAfterRead is set to true. | string | ||
| destinationBucketSuffix | Destination Bucket Suffix | Define the destination bucket suffix to use when an object must be moved, and moveAfterRead is set to true. | string | ||
| forcePathStyle | Force Path Style | Forces path style when accessing AWS S3 buckets. | boolean | False | |
| ignoreBody | Ignore Body |
If true, the S3 Object body is ignored. Setting this to true overrides any behavior defined by the | boolean | False | |
| maxMessagesPerPoll | Max Messages Per Poll | Gets the maximum number of messages as a limit to poll at each polling. Gets the maximum number of messages as a limit to poll at each polling. The default value is 10. Use 0 or a negative number to set it as unlimited. | integer | 10 | |
| moveAfterRead | Move Objects After Delete | Move objects from S3 bucket to a different bucket after they have been retrieved. | boolean | False | |
| overrideEndpoint | Endpoint Overwrite |
Select this option to override the endpoint URI. To use this option, you must also provide a URI for the | boolean | False | |
| prefix | Prefix | The AWS S3 bucket prefix to consider while searching. | string | folder/ | |
| profileCredentialsName | Profile Credentials Name | If using a profile credentials provider this parameter sets the profile name. | string | ||
| secretKey | Secret Key | The secret key obtained from AWS. | string | ||
| sessionToken | Session Token | Amazon AWS Session Token used when the user needs to assume a IAM role. | string | ||
| uriEndpointOverride | Overwrite Endpoint URI |
The overriding endpoint URI. To use this option, you must also select the | string | ||
| useDefaultCredentialsProvider | Default Credentials Provider | If true, the S3 client loads credentials through a default credentials provider. If false, it uses the basic authentication method (access key and secret key). | boolean | False | |
| useProfileCredentialsProvider | Profile Credentials Provider | Set whether the S3 client should expect to load credentials through a profile credentials provider. | boolean | False | |
| useSessionCredentials | Session Credentials | Set whether the S3 client should expect to use Session Credentials. This is useful in situation in which the user needs to assume a IAM role for doing operations in S3. | boolean | False |
* = Fields marked with an asterisk are mandatory.
16.4. Dependencies Copy linkLink copied to clipboard!
16.4.1. Quarkus dependencies Copy linkLink copied to clipboard!
<dependencies>
<dependency>
<groupId>org.apache.camel.kamelets</groupId>
<artifactId>camel-kamelets-utils</artifactId>
<version>4.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-aws-s3-source</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-aws2-s3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-kamelet</artifactId>
</dependency>
</dependencies>
16.5. Usage Copy linkLink copied to clipboard!
16.5.1. Camel JBang usage Copy linkLink copied to clipboard!
16.5.1.1. Prerequisites for JBang Copy linkLink copied to clipboard!
- Install JBang.
You have executed the following command:
jbang app install camel@apache/camel
16.5.1.2. Running a route with JBang Copy linkLink copied to clipboard!
Suppose you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:timer-source"
parameters:
period: 10000
message: 'test'
steps:
- to:
uri: "kamelet:log-sink"
You can now run it directly through the following command.
camel run route.yaml
16.5.2. Knative Source Copy linkLink copied to clipboard!
You can use the aws-s3-source Kamelet as a Knative source by binding it to a Knative object.
aws-s3-source-binding.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: aws-s3-source-binding
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: aws-s3-source
properties:
accessKey: "The Access Key"
bucketNameOrArn: "The Bucket Name"
region: "eu-west-1"
secretKey: "The Secret Key"
sink:
ref:
kind: Channel
apiVersion: messaging.knative.dev/v1
name: mychannel
16.5.3. Kafka Source Copy linkLink copied to clipboard!
You can use the aws-s3-source Kamelet as a Kafka source by binding it to a Kafka topic.
aws-s3-source-binding.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: aws-s3-source-binding
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: aws-s3-source
properties:
accessKey: "The Access Key"
bucketNameOrArn: "The Bucket Name"
region: "eu-west-1"
secretKey: "The Secret Key"
sink:
ref:
kind: KafkaTopic
apiVersion: kafka.strimzi.io/v1beta1
name: my-topic