Camel Components

AWS Athena

Since Camel 3.4

Only producer is supported

The AWS2 Athena component supports running queries with AWS Athena and working with results.

Prerequisites

You must have a valid Amazon Web Services developer account, and be signed up to use Amazon Athena. More information is available at AWS Athena.

URI Format

aws2-athena://label[?options]

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, *.yaml files, 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 Athena component supports the following options which are listed below.

Name Description Default Type

configuration (producer)

The component configuration.

Athena2Configuration

database (producer)

The name of the database that startQueryExecution runs the query in, sent as the database of the query execution context. If not set, no database is sent. The CamelAwsAthenaDatabase header takes precedence over this option.

String

delay (producer)

The time in milliseconds between two checks of the state of the query, after the first one. Used only when waitTimeout is above 0. The CamelAwsAthenaDelay header takes precedence over this option.

2000

long

initialDelay (producer)

The time in milliseconds before startQueryExecution checks the state of the query for the first time; the checks after a retry wait delay instead. Used only when waitTimeout is above 0. The CamelAwsAthenaInitialDelay header takes precedence over this option.

1000

long

lazyStartProducer (producer)

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

maxAttempts (producer)

The maximum number of times that startQueryExecution starts the query; 1, the default, makes no retries. The query is started again only when it completed without success and the failure matches the retry option, which requires waitTimeout above 0. A query still running when waitTimeout is up is not started again. A value below 1 fails the exchange. The CamelAwsAthenaMaxAttempts header takes precedence over this option.

1

int

maxResults (producer)

The maximum number of results that one request returns: rows for getQueryResults (1 to 1000), query execution IDs for listQueryExecutions (0 to 50). With outputType StreamList, it is the size of each page. If not set, Athena uses its own default. The CamelAwsAthenaMaxResults header takes precedence over this option.

Integer

nextToken (producer)

The token of the page of results to read, which is the NextToken of an earlier response of getQueryResults or listQueryExecutions. If not set, the first page is read. The CamelAwsAthenaNextToken header takes precedence over this option.

String

operation (producer)

The operation that the producer performs. The CamelAwsAthenaOperation header takes precedence over this option.

Enum values:

  • getQueryExecution

  • getQueryResults

  • listQueryExecutions

  • startQueryExecution

startQueryExecution

Athena2Operations

outputLocation (producer)

The location in Amazon S3 where startQueryExecution stores the query results, such as s3://path/to/query/bucket/, ending with a forward slash. startQueryExecution fails if neither this option nor the CamelAwsAthenaOutputLocation header, which takes precedence, is set. If the workgroup enforces its own configuration, Athena uses the location of the workgroup.

String

outputType (producer)

How getQueryResults returns the results. StreamList, the default, returns a GetQueryResultsIterable that pages through all results, calling Athena as it is read. SelectList returns one page as a GetQueryResultsResponse, at most 1000 rows, and sets the CamelAwsAthenaNextToken header to the token of the next page. S3Pointer returns the S3 location of the results file as text. The CamelAwsAthenaOutputType header takes precedence over this option.

Enum values:

  • StreamList

  • SelectList

  • S3Pointer

StreamList

Athena2OutputType

overrideEndpoint (producer)

Whether the client sends its requests to the URI of uriEndpointOverride instead of the endpoint of the AWS region. Without uriEndpointOverride this option has no effect.

false

boolean

queryExecutionId (producer)

The ID of the query execution that getQueryExecution and getQueryResults read. The CamelAwsAthenaQueryExecutionId header, which startQueryExecution sets, takes precedence over this option. These operations fail if neither is set.

String

queryString (producer)

The SQL query to run. The CamelAwsAthenaQueryString header takes precedence over this option, and when useMessageBodyForSql is enabled, so does a non-empty message body. Except for simple queries, prefer setting the query in the header to avoid having to deal with URL encoding issues.

String

region (producer)

The AWS region of Athena, as a lowercase region ID such as eu-west-1, which is the value of Region.EU_WEST_1.id(). If not set, the AWS SDK takes the region from its default region provider chain, such as the aws.region system property or the AWS_REGION environment variable.

Enum values:

  • ap-south-2

  • ap-south-1

  • eu-south-1

  • eu-south-2

  • us-gov-east-1

  • me-central-1

  • il-central-1

  • ca-central-1

  • eu-central-1

  • us-iso-west-1

  • eu-central-2

  • eu-isoe-west-1

  • us-west-1

  • us-west-2

  • af-south-1

  • eu-north-1

  • eu-west-3

  • eu-west-2

  • eu-west-1

  • ap-northeast-3

  • ap-northeast-2

  • ap-northeast-1

  • me-south-1

  • sa-east-1

  • ap-east-1

  • cn-north-1

  • ca-west-1

  • us-gov-west-1

  • ap-southeast-1

  • ap-southeast-2

  • us-iso-east-1

  • ap-southeast-3

  • ap-southeast-4

  • us-east-1

  • us-east-2

  • cn-northwest-1

  • us-isob-east-1

  • aws-global

  • aws-cn-global

  • aws-us-gov-global

  • aws-iso-global

  • aws-iso-b-global

String

resetWaitTimeoutOnRetry (producer)

Whether waitTimeout starts again with each attempt of the query. If true, each attempt waits up to waitTimeout, so the total wait can reach waitTimeout times maxAttempts. If false, waitTimeout is the limit for all attempts together, counted from the first start. The CamelAwsAthenaResetWaitTimeoutOnRetry header takes precedence over this option.

true

boolean

retry (producer)

Which failures of a completed query make startQueryExecution start it again, as a comma-separated list: never (the default) for no retries; always for every query that did not succeed; generic when the reason of the failure contains GENERIC_INTERNAL_ERROR; exhausted when the query exhausted the resources at this scale factor; retryable for both generic and exhausted. never, always and retryable cannot be combined with another value. Used only when maxAttempts is above 1 and waitTimeout above 0. The CamelAwsAthenaRetry header takes precedence over this option.

Enum values:

  • never

  • always

  • retryable

  • exhausted

  • generic

never

String

uriEndpointOverride (producer)

The URI that the client sends its requests to, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true.

String

useMessageBodyForSql (producer)

Whether to use the message body as the SQL query to run. When enabled, a non-empty message body takes precedence over the CamelAwsAthenaQueryString header and the queryString option. When disabled, the message body is not used as the query.

false

boolean

waitTimeout (producer)

The maximum time in milliseconds that startQueryExecution waits for the query to complete, checking its state after initialDelay and then every delay. 0, the default, does not wait: the producer returns after starting the query, without its state, and makes no retries. A query that fails, or still runs when the time is up, does not fail the exchange: check the CamelAwsAthenaQueryExecutionState header. A negative value fails the exchange. The CamelAwsAthenaWaitTimeout header takes precedence over this option.

0

long

workGroup (producer)

The name of the workgroup that startQueryExecution runs the query in, and whose query executions listQueryExecutions lists. If not set, Athena uses the primary workgroup. The CamelAwsAthenaWorkGroup header takes precedence over this option.

String

amazonAthenaClient (advanced)

Autowired To use a custom software.amazon.awssdk.services.athena.AthenaClient. When this option is set or autowired, the endpoint does not build a client of its own, so the credentials, region, proxy and endpoint override options are not used. The endpoint does not close a client that is set or autowired.

AthenaClient

autowiredEnabled (advanced)

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

clientRequestToken (advanced)

The idempotency token of startQueryExecution, a unique case-sensitive string of 32 to 128 characters. If not set, the AWS SDK generates a new token for each request. For a token it has seen before, Athena starts no new query and returns the same query execution ID, or fails if the query string differs. A token set here is sent with every exchange and every retry. The CamelAwsAthenaClientRequestToken header takes precedence over this option.

String

includeTrace (advanced)

Whether startQueryExecution adds an SQL comment line (starting with --) before the query, with the URI of the from endpoint, the exchange ID and the route ID as JSON, to trace the query back to the exchange. The CamelAwsAthenaIncludeTrace header takes precedence over this option.

false

boolean

healthCheckConsumerEnabled (health)

Used for enabling or disabling all consumer based health checks from this component.

true

boolean

healthCheckProducerEnabled (health)

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

proxyHost (proxy)

The host name of the proxy that the client sends its requests through. The proxy is used only when proxyPort is set as well.

String

proxyPort (proxy)

The port of the proxy that the client sends its requests through. The proxy is used only when proxyHost is set as well.

Integer

proxyProtocol (proxy)

The protocol that the client uses to connect to the proxy. It is used only when proxyHost and proxyPort are set.

Enum values:

  • HTTP

  • HTTPS

HTTPS

Protocol

accessKey (security)

The access key ID of the AWS credentials. The client uses it with secretKey as static credentials, or with secretKey and sessionToken when useSessionCredentials is true.

String

encryptionOption (security)

The encryption of the query results that startQueryExecution stores in S3: SSE_S3, SSE_KMS or CSE_KMS. If not set, no encryption configuration is sent with the query. If the workgroup enforces its own configuration, Athena uses the encryption of the workgroup. The CamelAwsAthenaEncryptionOption header takes precedence over this option.

Enum values:

  • SSE_S3

  • SSE_KMS

  • CSE_KMS

  • null

EncryptionOption

kmsKey (security)

The ARN or ID of the KMS key for the SSE_KMS and CSE_KMS encryption options. It requires an encryption option: startQueryExecution fails if kmsKey is set without one. The CamelAwsAthenaKmsKey header takes precedence over this option.

String

profileCredentialsName (security)

The name of the profile that the client loads when useProfileCredentialsProvider is true. If not set, the AWS SDK uses the profile that the AWS_PROFILE environment variable or the aws.profile system property names, or else the profile named default.

String

secretKey (security)

The secret access key of the AWS credentials, which the client uses together with accessKey.

String

sessionToken (security)

The session token of temporary AWS credentials, for example from assuming an IAM role. The client uses it only when useSessionCredentials is true, together with accessKey and secretKey.

String

trustAllCertificates (security)

Whether the client trusts all TLS certificates without validating them. It applies to every connection of the client, not only when the endpoint is overridden.

false

boolean

useDefaultCredentialsProvider (security)

Whether the client loads the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the web identity token, the profile files, and the container and instance metadata. It takes precedence over the other credentials options.

false

boolean

useProfileCredentialsProvider (security)

Whether the client loads the credentials from a profile of the AWS config and credentials files, the one that profileCredentialsName names. It takes precedence over useSessionCredentials, accessKey and secretKey, but not over useDefaultCredentialsProvider.

false

boolean

useSessionCredentials (security)

Whether the client uses temporary session credentials made of accessKey, secretKey and sessionToken, for example after assuming an IAM role. All three are required: if one of the three is missing, creating the client fails.

false

boolean

Endpoint Options

The AWS Athena endpoint is configured using URI syntax:

aws2-athena:label

With the following path and query parameters:

Path Parameters

Name Description Default Type

label (producer)

Required A logical name of the endpoint, which you choose freely. The producer does not use it.

String

Query Parameters

Name Description Default Type

database (producer)

The name of the database that startQueryExecution runs the query in, sent as the database of the query execution context. If not set, no database is sent. The CamelAwsAthenaDatabase header takes precedence over this option.

String

delay (producer)

The time in milliseconds between two checks of the state of the query, after the first one. Used only when waitTimeout is above 0. The CamelAwsAthenaDelay header takes precedence over this option.

2000

long

initialDelay (producer)

The time in milliseconds before startQueryExecution checks the state of the query for the first time; the checks after a retry wait delay instead. Used only when waitTimeout is above 0. The CamelAwsAthenaInitialDelay header takes precedence over this option.

1000

long

maxAttempts (producer)

The maximum number of times that startQueryExecution starts the query; 1, the default, makes no retries. The query is started again only when it completed without success and the failure matches the retry option, which requires waitTimeout above 0. A query still running when waitTimeout is up is not started again. A value below 1 fails the exchange. The CamelAwsAthenaMaxAttempts header takes precedence over this option.

1

int

maxResults (producer)

The maximum number of results that one request returns: rows for getQueryResults (1 to 1000), query execution IDs for listQueryExecutions (0 to 50). With outputType StreamList, it is the size of each page. If not set, Athena uses its own default. The CamelAwsAthenaMaxResults header takes precedence over this option.

Integer

nextToken (producer)

The token of the page of results to read, which is the NextToken of an earlier response of getQueryResults or listQueryExecutions. If not set, the first page is read. The CamelAwsAthenaNextToken header takes precedence over this option.

String

operation (producer)

The operation that the producer performs. The CamelAwsAthenaOperation header takes precedence over this option.

Enum values:

  • getQueryExecution

  • getQueryResults

  • listQueryExecutions

  • startQueryExecution

startQueryExecution

Athena2Operations

outputLocation (producer)

The location in Amazon S3 where startQueryExecution stores the query results, such as s3://path/to/query/bucket/, ending with a forward slash. startQueryExecution fails if neither this option nor the CamelAwsAthenaOutputLocation header, which takes precedence, is set. If the workgroup enforces its own configuration, Athena uses the location of the workgroup.

String

outputType (producer)

How getQueryResults returns the results. StreamList, the default, returns a GetQueryResultsIterable that pages through all results, calling Athena as it is read. SelectList returns one page as a GetQueryResultsResponse, at most 1000 rows, and sets the CamelAwsAthenaNextToken header to the token of the next page. S3Pointer returns the S3 location of the results file as text. The CamelAwsAthenaOutputType header takes precedence over this option.

Enum values:

  • StreamList

  • SelectList

  • S3Pointer

StreamList

Athena2OutputType

overrideEndpoint (producer)

Whether the client sends its requests to the URI of uriEndpointOverride instead of the endpoint of the AWS region. Without uriEndpointOverride this option has no effect.

false

boolean

queryExecutionId (producer)

The ID of the query execution that getQueryExecution and getQueryResults read. The CamelAwsAthenaQueryExecutionId header, which startQueryExecution sets, takes precedence over this option. These operations fail if neither is set.

String

queryString (producer)

The SQL query to run. The CamelAwsAthenaQueryString header takes precedence over this option, and when useMessageBodyForSql is enabled, so does a non-empty message body. Except for simple queries, prefer setting the query in the header to avoid having to deal with URL encoding issues.

String

region (producer)

The AWS region of Athena, as a lowercase region ID such as eu-west-1, which is the value of Region.EU_WEST_1.id(). If not set, the AWS SDK takes the region from its default region provider chain, such as the aws.region system property or the AWS_REGION environment variable.

Enum values:

  • ap-south-2

  • ap-south-1

  • eu-south-1

  • eu-south-2

  • us-gov-east-1

  • me-central-1

  • il-central-1

  • ca-central-1

  • eu-central-1

  • us-iso-west-1

  • eu-central-2

  • eu-isoe-west-1

  • us-west-1

  • us-west-2

  • af-south-1

  • eu-north-1

  • eu-west-3

  • eu-west-2

  • eu-west-1

  • ap-northeast-3

  • ap-northeast-2

  • ap-northeast-1

  • me-south-1

  • sa-east-1

  • ap-east-1

  • cn-north-1

  • ca-west-1

  • us-gov-west-1

  • ap-southeast-1

  • ap-southeast-2

  • us-iso-east-1

  • ap-southeast-3

  • ap-southeast-4

  • us-east-1

  • us-east-2

  • cn-northwest-1

  • us-isob-east-1

  • aws-global

  • aws-cn-global

  • aws-us-gov-global

  • aws-iso-global

  • aws-iso-b-global

String

resetWaitTimeoutOnRetry (producer)

Whether waitTimeout starts again with each attempt of the query. If true, each attempt waits up to waitTimeout, so the total wait can reach waitTimeout times maxAttempts. If false, waitTimeout is the limit for all attempts together, counted from the first start. The CamelAwsAthenaResetWaitTimeoutOnRetry header takes precedence over this option.

true

boolean

retry (producer)

Which failures of a completed query make startQueryExecution start it again, as a comma-separated list: never (the default) for no retries; always for every query that did not succeed; generic when the reason of the failure contains GENERIC_INTERNAL_ERROR; exhausted when the query exhausted the resources at this scale factor; retryable for both generic and exhausted. never, always and retryable cannot be combined with another value. Used only when maxAttempts is above 1 and waitTimeout above 0. The CamelAwsAthenaRetry header takes precedence over this option.

Enum values:

  • never

  • always

  • retryable

  • exhausted

  • generic

never

String

uriEndpointOverride (producer)

The URI that the client sends its requests to, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true.

String

useMessageBodyForSql (producer)

Whether to use the message body as the SQL query to run. When enabled, a non-empty message body takes precedence over the CamelAwsAthenaQueryString header and the queryString option. When disabled, the message body is not used as the query.

false

boolean

waitTimeout (producer)

The maximum time in milliseconds that startQueryExecution waits for the query to complete, checking its state after initialDelay and then every delay. 0, the default, does not wait: the producer returns after starting the query, without its state, and makes no retries. A query that fails, or still runs when the time is up, does not fail the exchange: check the CamelAwsAthenaQueryExecutionState header. A negative value fails the exchange. The CamelAwsAthenaWaitTimeout header takes precedence over this option.

0

long

workGroup (producer)

The name of the workgroup that startQueryExecution runs the query in, and whose query executions listQueryExecutions lists. If not set, Athena uses the primary workgroup. The CamelAwsAthenaWorkGroup header takes precedence over this option.

String

lazyStartProducer (producer (advanced))

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

amazonAthenaClient (advanced)

Autowired To use a custom software.amazon.awssdk.services.athena.AthenaClient. When this option is set or autowired, the endpoint does not build a client of its own, so the credentials, region, proxy and endpoint override options are not used. The endpoint does not close a client that is set or autowired.

AthenaClient

clientRequestToken (advanced)

The idempotency token of startQueryExecution, a unique case-sensitive string of 32 to 128 characters. If not set, the AWS SDK generates a new token for each request. For a token it has seen before, Athena starts no new query and returns the same query execution ID, or fails if the query string differs. A token set here is sent with every exchange and every retry. The CamelAwsAthenaClientRequestToken header takes precedence over this option.

String

includeTrace (advanced)

Whether startQueryExecution adds an SQL comment line (starting with --) before the query, with the URI of the from endpoint, the exchange ID and the route ID as JSON, to trace the query back to the exchange. The CamelAwsAthenaIncludeTrace header takes precedence over this option.

false

boolean

proxyHost (proxy)

The host name of the proxy that the client sends its requests through. The proxy is used only when proxyPort is set as well.

String

proxyPort (proxy)

The port of the proxy that the client sends its requests through. The proxy is used only when proxyHost is set as well.

Integer

proxyProtocol (proxy)

The protocol that the client uses to connect to the proxy. It is used only when proxyHost and proxyPort are set.

Enum values:

  • HTTP

  • HTTPS

HTTPS

Protocol

accessKey (security)

The access key ID of the AWS credentials. The client uses it with secretKey as static credentials, or with secretKey and sessionToken when useSessionCredentials is true.

String

encryptionOption (security)

The encryption of the query results that startQueryExecution stores in S3: SSE_S3, SSE_KMS or CSE_KMS. If not set, no encryption configuration is sent with the query. If the workgroup enforces its own configuration, Athena uses the encryption of the workgroup. The CamelAwsAthenaEncryptionOption header takes precedence over this option.

Enum values:

  • SSE_S3

  • SSE_KMS

  • CSE_KMS

  • null

EncryptionOption

kmsKey (security)

The ARN or ID of the KMS key for the SSE_KMS and CSE_KMS encryption options. It requires an encryption option: startQueryExecution fails if kmsKey is set without one. The CamelAwsAthenaKmsKey header takes precedence over this option.

String

profileCredentialsName (security)

The name of the profile that the client loads when useProfileCredentialsProvider is true. If not set, the AWS SDK uses the profile that the AWS_PROFILE environment variable or the aws.profile system property names, or else the profile named default.

String

secretKey (security)

The secret access key of the AWS credentials, which the client uses together with accessKey.

String

sessionToken (security)

The session token of temporary AWS credentials, for example from assuming an IAM role. The client uses it only when useSessionCredentials is true, together with accessKey and secretKey.

String

trustAllCertificates (security)

Whether the client trusts all TLS certificates without validating them. It applies to every connection of the client, not only when the endpoint is overridden.

false

boolean

useDefaultCredentialsProvider (security)

Whether the client loads the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the web identity token, the profile files, and the container and instance metadata. It takes precedence over the other credentials options.

false

boolean

useProfileCredentialsProvider (security)

Whether the client loads the credentials from a profile of the AWS config and credentials files, the one that profileCredentialsName names. It takes precedence over useSessionCredentials, accessKey and secretKey, but not over useDefaultCredentialsProvider.

false

boolean

useSessionCredentials (security)

Whether the client uses temporary session credentials made of accessKey, secretKey and sessionToken, for example after assuming an IAM role. All three are required: if one of the three is missing, creating the client fails.

false

boolean

Message Headers

The AWS Athena component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelAwsAthenaOperation (all)

Constant: OPERATION

The operation to perform: getQueryExecution, getQueryResults, listQueryExecutions or startQueryExecution. It takes precedence over the operation option.

Enum values:

  • getQueryExecution

  • getQueryResults

  • listQueryExecutions

  • startQueryExecution

startQueryExecution

Athena2Operations

CamelAwsAthenaDatabase (startQueryExecution)

Constant: DATABASE

The name of the database that the query runs in. It takes precedence over the database option.

String

CamelAwsAthenaQueryExecutionId (getQueryExecution getQueryResults startQueryExecution)

Constant: QUERY_EXECUTION_ID

The ID of the query execution. getQueryExecution and getQueryResults read the query execution with this ID, and it takes precedence over the queryExecutionId option. The three operations set it to the ID of the query execution.

String

CamelAwsAthenaWorkGroup (listQueryExecutions startQueryExecution)

Constant: WORK_GROUP

The name of the workgroup that startQueryExecution runs the query in, and whose query executions listQueryExecutions lists. It takes precedence over the workGroup option.

String

CamelAwsAthenaNextToken (getQueryResults listQueryExecutions)

Constant: NEXT_TOKEN

The token of the next page of results. getQueryResults with outputType SelectList and listQueryExecutions set it from the response, null on the last page, and read it to get that page. It takes precedence over the nextToken option.

String

CamelAwsAthenaMaxResults (getQueryResults listQueryExecutions)

Constant: MAX_RESULTS

The maximum number of results that one request returns: rows for getQueryResults (1 to 1000), query execution IDs for listQueryExecutions (0 to 50). It takes precedence over the maxResults option.

Integer

CamelAwsAthenaIsTruncated (getQueryResults listQueryExecutions)

Constant: IS_TRUNCATED

Whether more results are available: true when the response has a next token, which is then in the CamelAwsAthenaNextToken header. getQueryResults sets it only with outputType SelectList.

Boolean

CamelAwsAthenaIncludeTrace (startQueryExecution)

Constant: INCLUDE_TRACE

Whether to add an SQL comment line (starting with --) before the query, with the URI of the from endpoint, the exchange ID and the route ID as JSON. It takes precedence over the includeTrace option.

boolean

CamelAwsAthenaOutputLocation (getQueryExecution getQueryResults startQueryExecution)

Constant: OUTPUT_LOCATION

The location in Amazon S3 where startQueryExecution stores the query results, such as s3://path/to/query/bucket/, ending with a forward slash. It takes precedence over the outputLocation option. getQueryExecution, getQueryResults with outputType S3Pointer, and startQueryExecution set it to the S3 location of the results file of the query: null when the query has no result configuration, or when startQueryExecution does not wait for the query (waitTimeout 0).

String

CamelAwsAthenaOutputType (getQueryResults)

Constant: OUTPUT_TYPE

How getQueryResults returns the results: StreamList, SelectList or S3Pointer. It takes precedence over the outputType option.

Enum values:

  • StreamList

  • SelectList

  • S3Pointer

Athena2OutputType

CamelAwsAthenaQueryExecutionState (getQueryExecution getQueryResults startQueryExecution)

Constant: QUERY_EXECUTION_STATE

The state of the query execution, such as QUEUED, RUNNING, SUCCEEDED, FAILED or CANCELLED. getQueryExecution, getQueryResults with outputType S3Pointer, and startQueryExecution set it. startQueryExecution sets it to null when it does not wait for the query (waitTimeout 0).

Enum values:

  • QUEUED

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELLED

  • null

QueryExecutionState

CamelAwsAthenaClientRequestToken (startQueryExecution)

Constant: CLIENT_REQUEST_TOKEN

The idempotency token of the query, a unique case-sensitive string of 32 to 128 characters. For a token it has seen before, Athena starts no new query and returns the same query execution ID. It takes precedence over the clientRequestToken option.

String

CamelAwsAthenaQueryString (startQueryExecution)

Constant: QUERY_STRING

The SQL query to run. It takes precedence over the queryString option. When the useMessageBodyForSql option is enabled, a non-empty message body takes precedence over this header.

String

CamelAwsAthenaEncryptionOption (startQueryExecution)

Constant: ENCRYPTION_OPTION

The encryption of the query results in S3: SSE_S3, SSE_KMS or CSE_KMS. It takes precedence over the encryptionOption option.

Enum values:

  • SSE_S3

  • SSE_KMS

  • CSE_KMS

  • null

EncryptionOption

CamelAwsAthenaKmsKey (startQueryExecution)

Constant: KMS_KEY

The ARN or ID of the KMS key for the SSE_KMS and CSE_KMS encryption options. It takes precedence over the kmsKey option.

String

CamelAwsAthenaWaitTimeout (startQueryExecution)

Constant: WAIT_TIMEOUT

The maximum time in milliseconds to wait for the query to complete; 0 does not wait. It takes precedence over the waitTimeout option.

long

CamelAwsAthenaInitialDelay (startQueryExecution)

Constant: INITIAL_DELAY

The time in milliseconds before the first check of the state of the query. It takes precedence over the initialDelay option.

long

CamelAwsAthenaDelay (startQueryExecution)

Constant: DELAY

The time in milliseconds between two checks of the state of the query. It takes precedence over the delay option.

long

CamelAwsAthenaMaxAttempts (startQueryExecution)

Constant: MAX_ATTEMPTS

The maximum number of times to start the query; 1 makes no retries. It takes precedence over the maxAttempts option.

int

CamelAwsAthenaRetry (startQueryExecution)

Constant: RETRY

Which failures of a completed query start it again, as a comma-separated list of never, always, retryable, generic or exhausted. It takes precedence over the retry option.

String

CamelAwsAthenaResetWaitTimeoutOnRetry (startQueryExecution)

Constant: RESET_WAIT_TIMEOUT_ON_RETRY

Whether waitTimeout starts again with each attempt of the query. It takes precedence over the resetWaitTimeoutOnRetry option.

boolean

CamelAwsAthenaStartQueryExecutionAttempts (startQueryExecution)

Constant: START_QUERY_EXECUTION_ATTEMPTS

The number of times that the query was started, above 1 when it was retried.

int

CamelAwsAthenaStartQueryExecutionElapsedMillis (startQueryExecution)

Constant: START_QUERY_EXECUTION_ELAPSED_MILLIS

The time in milliseconds that startQueryExecution took, including the wait for the query to complete.

long

Message Body

The message body at each side of the AWS Athena 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

Producer input

any

The SQL of startQueryExecution, the default, as text: bytes, a stream or a file are read as text, a Map or a POJO is sent as its toString(). With no body the SQL comes from the CamelAwsAthenaQueryString header or the queryString option. The other operations do not use the body: they take the id of the query from the CamelAwsAthenaQueryExecutionId header, which startQueryExecution sets.

  • With operation=startQueryExecution: text, bytes, stream, file or null

Producer output

pojo

startQueryExecution, the default, leaves no body, with the id of the query in the CamelAwsAthenaQueryExecutionId header; with waitTimeout, the GetQueryExecutionResponse of the AWS SDK of the last check, whatever the state of the query. getQueryResults gives by outputType: for StreamList, the default, a GetQueryResultsIterable of the pages of rows, which calls Athena when it is read, such as by a split; for SelectList one page as a GetQueryResultsResponse; for S3Pointer the S3 location of the results as text. getQueryExecution and listQueryExecutions give the response of the AWS SDK.

  • With operation=startQueryExecution: null or pojo

  • With operation=getQueryResults: iterator, pojo or text

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 Athena component options

You have to provide the amazonAthenaClient in the Registry or your accessKey and secretKey to access the AWS Athena service.

Usage

Where the SQL comes from

The startQueryExecution operation, which is the default operation, runs the SQL of the CamelAwsAthenaQueryString header, and when the header is not set, the SQL of the queryString option.

The message body is used as the SQL only when the useMessageBodyForSql option is set to true. A non-empty body then takes precedence over the header and the option. When no SQL is found, the exchange fails with an IllegalArgumentException.

For example, to run the same query each time a message arrives, whatever its body:

  • Java

  • XML

  • YAML

from("direct:start")
    .setHeader(Athena2Constants.QUERY_STRING, constant("SELECT 1"))
    .to("aws2-athena://label?outputLocation=s3://bucket/path/")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelAwsAthenaQueryString">
    <constant>SELECT 1</constant>
  </setHeader>
  <to uri="aws2-athena://label?outputLocation=s3://bucket/path/"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelAwsAthenaQueryString
            expression:
              constant:
                expression: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              outputLocation: s3://bucket/path/
        - to:
            uri: mock:result

The examples below set the SQL in the message body, so they set useMessageBodyForSql=true.

Examples

Producer Examples

For example, to run a simple query, wait up to 60 seconds for completion, and log the results:

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?useMessageBodyForSql=true&waitTimeout=60000&outputLocation=s3://bucket/path/")
    .to("aws2-athena://label?operation=getQueryResults&outputType=StreamList")
    .split(body()).streaming()
    .to("log:out")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setBody>
    <constant>SELECT 1</constant>
  </setBody>
  <to uri="aws2-athena://label?useMessageBodyForSql=true&amp;waitTimeout=60000&amp;outputLocation=s3://bucket/path/"/>
  <to uri="aws2-athena://label?operation=getQueryResults&amp;outputType=StreamList"/>
  <split streaming="true">
    <simple>${body}</simple>
    <to uri="log:out"/>
    <to uri="mock:result"/>
  </split>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              useMessageBodyForSql: true
              waitTimeout: "60000"
              outputLocation: s3://bucket/path/
        - to:
            uri: aws2-athena://label
            parameters:
              operation: getQueryResults
              outputType: StreamList
        - split:
            simple: "${body}"
            streaming: true
            steps:
              - to:
                  uri: log:out
              - to:
                  uri: mock:result

Similarly, running the query and returning a path to the results in S3:

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?useMessageBodyForSql=true&waitTimeout=60000&outputLocation=s3://bucket/path/")
    .to("aws2-athena://label?operation=getQueryResults&outputType=S3Pointer")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setBody>
    <constant>SELECT 1</constant>
  </setBody>
  <to uri="aws2-athena://label?useMessageBodyForSql=true&amp;waitTimeout=60000&amp;outputLocation=s3://bucket/path/"/>
  <to uri="aws2-athena://label?operation=getQueryResults&amp;outputType=S3Pointer"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              useMessageBodyForSql: true
              waitTimeout: "60000"
              outputLocation: s3://bucket/path/
        - to:
            uri: aws2-athena://label
            parameters:
              operation: getQueryResults
              outputType: S3Pointer
        - to:
            uri: mock:result

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.accessKeyId and aws.secretKey.

  • Environment variables - AWS_ACCESS_KEY_ID and AWS_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_URI is 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

Athena Producer operations

The Camel-AWS Athena component provides the following operation on the producer side:

  • getQueryExecution

  • getQueryResults

  • listQueryExecutions

  • startQueryExecution

Advanced AmazonAthena configuration

If your Camel Application is running behind a firewall or if you need to have more control over the AthenaClient instance configuration, you can create your own instance and refer to it in your Camel aws2-athena component configuration:

  • Java

  • XML

  • YAML

from("direct:start")
    .to("aws2-athena://MyQuery?amazonAthenaClient=#client")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <to uri="aws2-athena://MyQuery?amazonAthenaClient=#client"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: aws2-athena://MyQuery
            parameters:
              amazonAthenaClient: "#client"
        - to:
            uri: mock:result

Overriding query parameters with message headers

Message headers listed in "Message headers evaluated by the Athena producer" override the corresponding query parameters listed in "Query Parameters".

For example:

  • Java

  • XML

  • YAML

from("direct:start")
     .setHeader(Athena2Constants.OUTPUT_LOCATION, constant("s3://other/location/"))
     .to("aws2-athena:label?outputLocation=s3://foo/bar/")
     .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setHeader name="CamelAwsAthenaOutputLocation">
    <constant>s3://other/location/</constant>
  </setHeader>
  <to uri="aws2-athena:label?outputLocation=s3://foo/bar/"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setHeader:
            name: CamelAwsAthenaOutputLocation
            constant: "s3://other/location/"
        - to:
            uri: aws2-athena:label
            parameters:
              outputLocation: "s3://foo/bar/"
        - to:
            uri: mock:result

Will cause the output location to be s3://other/location/.

The CamelAwsAthenaOutputLocation and CamelAwsAthenaNextToken headers are also results of the operations. A result is not taken as the input of a later operation in the same route:

  • The CamelAwsAthenaOutputLocation header set by getQueryExecution, by getQueryResults with S3Pointer, and by startQueryExecution with a waitTimeout is the file with the results of that query. A later startQueryExecution does not use it, and puts its results under the outputLocation option instead.

  • The CamelAwsAthenaNextToken header that listQueryExecutions sets is used only by a later listQueryExecutions, and the one that getQueryResults sets only by a later getQueryResults for the same query.

A header that the route sets itself is always used.

Athena Producer Operation examples

  • getQueryExecution: this operation returns information about a query given its query execution ID

  • Java

  • XML

  • YAML

from("direct:start")
    .to("aws2-athena://label?operation=getQueryExecution&queryExecutionId=11111111-1111-1111-1111-111111111111")
    .to("mock:result");
<route>
    <from uri="direct:start"/>
    <to uri="aws2-athena://label?operation=getQueryExecution&amp;queryExecutionId=11111111-1111-1111-1111-111111111111"/>
    <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: aws2-athena://label
            parameters:
              operation: getQueryExecution
              queryExecutionId: 11111111-1111-1111-1111-111111111111
        - to:
            uri: mock:result

The preceding example will yield a GetQueryExecutionResponse in the body, whose queryExecution() is the Athena QueryExecution.

The getQueryExecution operation also supports retrieving the query execution ID from a header (CamelAwsAthenaQueryExecutionId), and since startQueryExecution sets the same header, upon starting a query, these operations can be used together:

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?operation=startQueryExecution&useMessageBodyForSql=true&outputLocation=s3://bucket/path/")
    .to("aws2-athena://label?operation=getQueryExecution")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setBody>
    <constant>SELECT 1</constant>
  </setBody>
  <to uri="aws2-athena://label?operation=startQueryExecution&amp;useMessageBodyForSql=true&amp;outputLocation=s3://bucket/path/"/>
  <to uri="aws2-athena://label?operation=getQueryExecution"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              operation: startQueryExecution
              useMessageBodyForSql: true
              outputLocation: s3://bucket/path/
        - to:
            uri: aws2-athena://label
            parameters:
              operation: getQueryExecution
        - to:
            uri: mock:result

The preceding example will yield a GetQueryExecutionResponse in the body for the query that was just started.

  • getQueryResults: this operation returns the results of a query that has succeeded. The results are returned in the body in one of three formats.

StreamList - the default - returns a GetQueryResultsIterable in the body that can page through all results:

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?operation=startQueryExecution&useMessageBodyForSql=true&waitTimeout=60000&outputLocation=s3://bucket/path/")
    .to("aws2-athena://label?operation=getQueryResults&outputType=StreamList")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setBody>
    <constant>SELECT 1</constant>
  </setBody>
  <to uri="aws2-athena://label?operation=startQueryExecution&amp;useMessageBodyForSql=true&amp;waitTimeout=60000&amp;outputLocation=s3://bucket/path/"/>
  <to uri="aws2-athena://label?operation=getQueryResults&amp;outputType=StreamList"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              operation: startQueryExecution
              useMessageBodyForSql: true
              waitTimeout: "60000"
              outputLocation: s3://bucket/path/
        - to:
            uri: aws2-athena://label
            parameters:
              operation: getQueryResults
              outputType: StreamList
        - to:
            uri: mock:result

The output of StreamList can be processed in various ways:

Java-only: AWS SDK GetQueryResultsResponse processing
from("direct:start")
    .setBody(constant("SELECT * FROM (VALUES (1, 'a'), (2, 'b')) AS t (id, name)"))
    .to("aws2-athena://label?operation=startQueryExecution&useMessageBodyForSql=true&waitTimeout=60000&outputLocation=s3://bucket/path/")
    .to("aws2-athena://label?operation=getQueryResults&outputType=StreamList")
    .split(body()).streaming()
    .process(exchange -> {
        GetQueryResultsResponse page = exchange.getMessage().getBody(GetQueryResultsResponse.class);
        for (Row row : page.resultSet().rows()) {
          String line = row.data().stream()
              .map(Datum::varCharValue)
              .collect(Collectors.joining(","));
          System.out.println(line);
        }
    })
    .to("mock:result");

The preceding example will print the results of the query as CSV to the console.

SelectList - returns a GetQueryResultsResponse in the body containing at most 1,000 rows, plus the NextToken value as a header (CamelAwsAthenaNextToken), which can be used for manual pagination of results:

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?operation=startQueryExecution&useMessageBodyForSql=true&waitTimeout=60000&outputLocation=s3://bucket/path/")
    .to("aws2-athena://label?operation=getQueryResults&outputType=SelectList")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setBody>
    <constant>SELECT 1</constant>
  </setBody>
  <to uri="aws2-athena://label?operation=startQueryExecution&amp;useMessageBodyForSql=true&amp;waitTimeout=60000&amp;outputLocation=s3://bucket/path/"/>
  <to uri="aws2-athena://label?operation=getQueryResults&amp;outputType=SelectList"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              operation: startQueryExecution
              useMessageBodyForSql: true
              waitTimeout: "60000"
              outputLocation: s3://bucket/path/
        - to:
            uri: aws2-athena://label
            parameters:
              operation: getQueryResults
              outputType: SelectList
        - to:
            uri: mock:result

The preceding example will return a GetQueryResultsResponse in the body plus the NextToken value as a header (CamelAwsAthenaNextToken), which can be used to manually page through the results 1,000 rows at a time.

S3Pointer - returns the S3 location of the results of the query as text:

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?operation=startQueryExecution&useMessageBodyForSql=true&waitTimeout=60000&outputLocation=s3://bucket/path/")
    .to("aws2-athena://label?operation=getQueryResults&outputType=S3Pointer")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setBody>
    <constant>SELECT 1</constant>
  </setBody>
  <to uri="aws2-athena://label?operation=startQueryExecution&amp;useMessageBodyForSql=true&amp;waitTimeout=60000&amp;outputLocation=s3://bucket/path/"/>
  <to uri="aws2-athena://label?operation=getQueryResults&amp;outputType=S3Pointer"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              operation: startQueryExecution
              useMessageBodyForSql: true
              waitTimeout: "60000"
              outputLocation: s3://bucket/path/
        - to:
            uri: aws2-athena://label
            parameters:
              operation: getQueryResults
              outputType: S3Pointer
        - to:
            uri: mock:result

The preceding example will return the S3 location of the results of the query as text in the body. The location will also be set in a header (CamelAwsAthenaOutputLocation). The location is given whatever the state of the query: the file is complete only when the CamelAwsAthenaQueryExecutionState header is SUCCEEDED. A query without a result configuration, as with managed query results, has no location, and the body and header are null.

  • listQueryExecutions: this operation returns a list of query execution IDs

  • Java

  • XML

  • YAML

from("direct:start")
    .to("aws2-athena://label?operation=listQueryExecutions")
    .to("mock:result");
<route>
    <from uri="direct:start"/>
    <to uri="aws2-athena://label?operation=listQueryExecutions"/>
    <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - to:
            uri: aws2-athena://label
            parameters:
              operation: listQueryExecutions
        - to:
            uri: mock:result

The preceding example will return a ListQueryExecutionsResponse in the body, whose queryExecutionIds() lists the ids of the query executions, plus the NextToken value as a header (CamelAwsAthenaNextToken) that can be used for manual pagination of results.

  • startQueryExecution: this operation starts the execution of a query. It supports waiting for the query to complete before proceeding, and retrying the query based on a set of configurable failure conditions:

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?operation=startQueryExecution&useMessageBodyForSql=true&outputLocation=s3://bucket/path/")
    .to("mock:result");
<route>
    <from uri="direct:start"/>
    <setBody>
        <constant>SELECT 1</constant>
    </setBody>
    <to uri="aws2-athena://label?operation=startQueryExecution&amp;useMessageBodyForSql=true&amp;outputLocation=s3://bucket/path/"/>
    <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              operation: startQueryExecution
              useMessageBodyForSql: true
              outputLocation: "s3://bucket/path/"
        - to:
            uri: mock:result

The preceding example will start the query SELECT 1 and configure the results to be saved to s3://bucket/path/, but will not wait for the query to complete. The body is then empty, and the id of the query is in the CamelAwsAthenaQueryExecutionId header.

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?operation=startQueryExecution&useMessageBodyForSql=true&waitTimeout=60000&outputLocation=s3://bucket/path/")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setBody>
    <constant>SELECT 1</constant>
  </setBody>
  <to uri="aws2-athena://label?operation=startQueryExecution&amp;useMessageBodyForSql=true&amp;waitTimeout=60000&amp;outputLocation=s3://bucket/path/"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              operation: startQueryExecution
              useMessageBodyForSql: true
              waitTimeout: "60000"
              outputLocation: s3://bucket/path/
        - to:
            uri: mock:result

The preceding example will start a query and wait up to 60 seconds for it to reach a status that indicates it is complete (one of SUCCEEDED, FAILED, CANCELLED, or UNKNOWN_TO_SDK_VERSION). Upon failure, the query would not be retried. The body is then the GetQueryExecutionResponse of the last check: a query that fails, or still runs after the wait, does not fail the exchange, so check the state of the query in the CamelAwsAthenaQueryExecutionState header.

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?operation=startQueryExecution&useMessageBodyForSql=true&waitTimeout=60000&initialDelay=10000&delay=1000&maxAttempts=3&retry=retryable&outputLocation=s3://bucket/path/")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setBody>
    <constant>SELECT 1</constant>
  </setBody>
  <to uri="aws2-athena://label?operation=startQueryExecution&amp;useMessageBodyForSql=true&amp;waitTimeout=60000&amp;initialDelay=10000&amp;delay=1000&amp;maxAttempts=3&amp;retry=retryable&amp;outputLocation=s3://bucket/path/"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              operation: startQueryExecution
              useMessageBodyForSql: true
              waitTimeout: "60000"
              initialDelay: "10000"
              delay: "1000"
              maxAttempts: 3
              retry: retryable
              outputLocation: s3://bucket/path/
        - to:
            uri: mock:result

The preceding example will start a query and wait up to 60 seconds for it to reach a status that indicates it is complete (one of SUCCEEDED, FAILED, CANCELLED, or UNKNOWN_TO_SDK_VERSION). Upon failure, the query would be automatically retried up to two more times if the failure state indicates the query may succeed upon retry (Athena queries that fail with states such as GENERIC_INTERNAL_ERROR or "resource limit exhaustion" will sometimes succeed if retried). While waiting for the query to complete, the query status would first be checked after an initial delay of 10 seconds, and subsequently every 1 second until the query completes.

Putting it all together

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?useMessageBodyForSql=true&waitTimeout=60000&maxAttempts=3&retry=retryable&outputLocation=s3://bucket/path/")
    .to("aws2-athena://label?operation=getQueryResults&outputType=StreamList")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setBody>
    <constant>SELECT 1</constant>
  </setBody>
  <to uri="aws2-athena://label?useMessageBodyForSql=true&amp;waitTimeout=60000&amp;maxAttempts=3&amp;retry=retryable&amp;outputLocation=s3://bucket/path/"/>
  <to uri="aws2-athena://label?operation=getQueryResults&amp;outputType=StreamList"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              useMessageBodyForSql: true
              waitTimeout: "60000"
              maxAttempts: 3
              retry: retryable
              outputLocation: s3://bucket/path/
        - to:
            uri: aws2-athena://label
            parameters:
              operation: getQueryResults
              outputType: StreamList
        - to:
            uri: mock:result

The preceding example will start the query and wait up to 60 seconds for it to complete. Upon completion, getQueryResults put the results of the query into the body of the message for further processing.

For the sake of completeness, a similar outcome could be achieved with the following:

  • Java

  • XML

  • YAML

from("direct:start")
    .setBody(constant("SELECT 1"))
    .to("aws2-athena://label?operation=startQueryExecution&useMessageBodyForSql=true&outputLocation=s3://bucket/path/")
    .loopDoWhile(simple("${header.CamelAwsAthenaQueryExecutionState} != 'SUCCEEDED'"))
      .delay(1_000)
      .to("aws2-athena://label?operation=getQueryExecution")
    .end()
    .to("aws2-athena://label?operation=getQueryResults&outputType=StreamList")
    .to("mock:result");
<route>
  <from uri="direct:start"/>
  <setBody>
    <constant>SELECT 1</constant>
  </setBody>
  <to uri="aws2-athena://label?operation=startQueryExecution&amp;useMessageBodyForSql=true&amp;outputLocation=s3://bucket/path/"/>
  <loop doWhile="true">
    <simple>${header.CamelAwsAthenaQueryExecutionState} != 'SUCCEEDED'</simple>
    <delay>
      <constant>1000</constant>
    </delay>
    <to uri="aws2-athena://label?operation=getQueryExecution"/>
  </loop>
  <to uri="aws2-athena://label?operation=getQueryResults&amp;outputType=StreamList"/>
  <to uri="mock:result"/>
</route>
- route:
    from:
      uri: direct:start
      steps:
        - setBody:
            constant: SELECT 1
        - to:
            uri: aws2-athena://label
            parameters:
              operation: startQueryExecution
              useMessageBodyForSql: true
              outputLocation: s3://bucket/path/
        - loop:
            doWhile: true
            simple: "${header.CamelAwsAthenaQueryExecutionState} != 'SUCCEEDED'"
            steps:
              - delay:
                  constant: "1000"
              - to:
                  uri: aws2-athena://label
                  parameters:
                    operation: getQueryExecution
        - to:
            uri: aws2-athena://label
            parameters:
              operation: getQueryResults
              outputType: StreamList
        - to:
            uri: mock:result

Caution: the preceding example would block indefinitely, however, if the query did not complete with a status of SUCCEEDED.

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-athena</artifactId>
    <version>${camel-version}</version>
</dependency>

where ${camel-version} must be replaced by the actual version of Camel.