AWS DynamoDB
Since Camel 3.1
Only producer is supported
The AWS2 DynamoDB component supports storing and retrieving data from/to Amazon’s DynamoDB service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon DynamoDB. More information is available at Amazon DynamoDB.
URI Format
aws2-ddb://tableName[?options]
The tableName is the DynamoDB table the operations work on. The CamelAwsDdbTableName header, when set, names another table for a message.
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 DynamoDB component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The component configuration. | Ddb2Configuration | ||
Whether GetItem, Query, Scan and ExecuteStatement use strongly consistent reads (ConsistentRead) instead of the eventually consistent reads that DynamoDB uses by default. A strongly consistent read uses twice the read capacity, and DynamoDB rejects it on a global secondary index. The CamelAwsDdbConsistentRead header replaces this option. | false | boolean | |
Whether the endpoint calls DescribeTable on its table when it starts, and waits until the table is ACTIVE, for at most 5 minutes. If the table does not exist, the endpoint creates it with the keyAttributeName, keyAttributeType, keyScalarType, readCapacity and writeCapacity options, and waits until it is ACTIVE. If false, the endpoint starts without calling DynamoDB. | true | boolean | |
The name of the key attribute of the table that the endpoint creates when it starts, if the table does not exist (see enabledInitialDescribeTable). It is not used for a table that exists. | String | ||
The key type (KeyType) of the key attribute of the table that the endpoint creates when it starts: HASH for a partition key. This attribute is the only key of the table, so it must be HASH. It is not used for a table that exists. | String | ||
The data type (ScalarAttributeType) of the key attribute of the table that the endpoint creates when it starts: S for String, N for Number or B for Binary. It is not used for a table that exists. | 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 | |
The operation to perform. The CamelAwsDdbOperation header replaces it for a message. Enum values:
| PutItem | Ddb2Operations | |
Whether to send the requests to the URI of the uriEndpointOverride option instead of the endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
The read capacity units (ReadCapacityUnits) of the provisioned throughput: of the table that the endpoint creates when it starts, and of the UpdateTable operation, where the CamelAwsDdbReadCapacity header replaces it. DynamoDB rejects both requests when the read or the write capacity is missing. | Long | ||
The AWS region of Amazon DynamoDB, as a region ID such as eu-west-1, which is the value of Region.EU_WEST_1.id(). If not set, the default region provider chain of the AWS SDK is used. Enum values:
| String | ||
The URI of the endpoint to use instead of the endpoint of the region, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
The write capacity units (WriteCapacityUnits) of the provisioned throughput: of the table that the endpoint creates when it starts, and of the UpdateTable operation, where the CamelAwsDdbWriteCapacity header replaces it. DynamoDB rejects both requests when the read or the write capacity is missing. | Long | ||
Autowired To use a custom software.amazon.awssdk.services.dynamodb.DynamoDbClient, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override and trustAllCertificates options are not used. The endpoint does not close a client that is set or autowired. | DynamoDbClient | ||
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 HTTP client of Amazon DynamoDB connects through. The proxy is used only when the proxyPort option is set too. | String | ||
The port of the proxy that the HTTP client of Amazon DynamoDB connects through. The proxy is used only when the proxyHost option is set too. | Integer | ||
The protocol that the HTTP client of Amazon DynamoDB uses to connect to the proxy. It is used only when the proxyHost and proxyPort options are set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless amazonDDBClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider 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 amazonDDBClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider 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 HTTP client of Amazon DynamoDB trusts every TLS certificate without checking it. It applies to any endpoint, not only to an overridden one, so use it only for testing, for example against 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 DynamoDB endpoint is configured using URI syntax:
aws2-ddb:tableName
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The name of the DynamoDB table that the operations work on. The CamelAwsDdbTableName header replaces it for a message. The endpoint checks, and if needed creates, this table when it starts (see enabledInitialDescribeTable). The batch, transaction and PartiQL operations name their tables in their own headers and do not use it. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Whether GetItem, Query, Scan and ExecuteStatement use strongly consistent reads (ConsistentRead) instead of the eventually consistent reads that DynamoDB uses by default. A strongly consistent read uses twice the read capacity, and DynamoDB rejects it on a global secondary index. The CamelAwsDdbConsistentRead header replaces this option. | false | boolean | |
Whether the endpoint calls DescribeTable on its table when it starts, and waits until the table is ACTIVE, for at most 5 minutes. If the table does not exist, the endpoint creates it with the keyAttributeName, keyAttributeType, keyScalarType, readCapacity and writeCapacity options, and waits until it is ACTIVE. If false, the endpoint starts without calling DynamoDB. | true | boolean | |
The name of the key attribute of the table that the endpoint creates when it starts, if the table does not exist (see enabledInitialDescribeTable). It is not used for a table that exists. | String | ||
The key type (KeyType) of the key attribute of the table that the endpoint creates when it starts: HASH for a partition key. This attribute is the only key of the table, so it must be HASH. It is not used for a table that exists. | String | ||
The data type (ScalarAttributeType) of the key attribute of the table that the endpoint creates when it starts: S for String, N for Number or B for Binary. It is not used for a table that exists. | String | ||
The operation to perform. The CamelAwsDdbOperation header replaces it for a message. Enum values:
| PutItem | Ddb2Operations | |
Whether to send the requests to the URI of the uriEndpointOverride option instead of the endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
The read capacity units (ReadCapacityUnits) of the provisioned throughput: of the table that the endpoint creates when it starts, and of the UpdateTable operation, where the CamelAwsDdbReadCapacity header replaces it. DynamoDB rejects both requests when the read or the write capacity is missing. | Long | ||
The AWS region of Amazon DynamoDB, as a region ID such as eu-west-1, which is the value of Region.EU_WEST_1.id(). If not set, the default region provider chain of the AWS SDK is used. Enum values:
| String | ||
The URI of the endpoint to use instead of the endpoint of the region, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
The write capacity units (WriteCapacityUnits) of the provisioned throughput: of the table that the endpoint creates when it starts, and of the UpdateTable operation, where the CamelAwsDdbWriteCapacity header replaces it. DynamoDB rejects both requests when the read or the write capacity is missing. | Long | ||
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 | |
Autowired To use a custom software.amazon.awssdk.services.dynamodb.DynamoDbClient, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override and trustAllCertificates options are not used. The endpoint does not close a client that is set or autowired. | DynamoDbClient | ||
The host name of the proxy that the HTTP client of Amazon DynamoDB connects through. The proxy is used only when the proxyPort option is set too. | String | ||
The port of the proxy that the HTTP client of Amazon DynamoDB connects through. The proxy is used only when the proxyHost option is set too. | Integer | ||
The protocol that the HTTP client of Amazon DynamoDB uses to connect to the proxy. It is used only when the proxyHost and proxyPort options are set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless amazonDDBClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider 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 amazonDDBClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider 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 HTTP client of Amazon DynamoDB trusts every TLS certificate without checking it. It applies to any endpoint, not only to an overridden one, so use it only for testing, for example against 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 DynamoDB component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAwsDdbAttributes (DeleteItem GetItem PutItem UpdateItem) Constant: | The attributes that the operation returned, as a map of attribute name to AttributeValue. For GetItem, the attributes of the item, or an empty map when no item has the key. For PutItem, UpdateItem and DeleteItem, the attributes that CamelAwsDdbReturnValues asks for, or an empty map when that header is not set. | Map | |
CamelAwsDdbAttributeNames (producer) Constant: | The names of the attributes that GetItem, Query and Scan read (the legacy AttributesToGet parameter). If not set, all attributes are read. DynamoDB rejects it in a request that also has an expression, such as CamelAwsDdbProjectExpression. | Collection | |
CamelAwsDdbBatchItems (producer) Constant: | The items that BatchGetItems reads: a map of table name to the KeysAndAttributes with the primary keys of the items of that table. | Map | |
CamelAwsDdbBatchResponse (BatchGetItems) Constant: | The items that BatchGetItems read: a map of table name to the list of items of that table, each a map of attribute name to AttributeValue. | Map | |
CamelAwsDdbConsistentRead (producer) Constant: | Whether GetItem, Query, Scan and ExecuteStatement use a strongly consistent read (true) or an eventually consistent read (false). It replaces the consistentRead option. | Boolean | |
CamelAwsDdbConsumedCapacity (Query Scan) Constant: | The capacity the operation consumed: its capacityUnits are the total Capacity Units of the table and its indexes used by the operation. | ConsumedCapacity | |
| Constant: | Number of items in the response. | Integer | |
CamelAwsDdbCreationDate (DeleteTable DescribeTable UpdateTable) Constant: | The date and time when the table was created. | Instant | |
CamelAwsDdbIndexName (producer) Constant: | The name of a local or global secondary index of the table that Query or Scan reads instead of the table. | String | |
| Constant: | The item that PutItem writes, as a map of attribute name to AttributeValue, which must include the attributes of the primary key. It replaces an item with the same primary key. | Map | |
| Constant: | The items that Query or Scan read, each a map of attribute name to AttributeValue. | List | |
CamelAwsDdbTableItemCount (DeleteTable DescribeTable UpdateTable) Constant: | The number of items in the table, which DynamoDB updates about every six hours. | Long | |
CamelAwsDdbNextToken (ExecuteStatement) Constant: | ExecuteStatement reads it as the token of the page to read, and sets it to the token of the next page (null on the last page). A loop can page through a statement with it; remove it before running another statement, as that statement would read this page of the earlier one. | String | |
| Constant: | The primary key of the item that GetItem, UpdateItem or DeleteItem works on, as a map of attribute name to AttributeValue with all attributes of the primary key. | Map | |
CamelAwsDdbKeyConditions (producer) Constant: | The conditions on the key attributes that select the items that Query reads, as a map of attribute name to Condition (the legacy KeyConditions parameter). Query requires a condition on the partition key. DynamoDB rejects it in a request that also has an expression, such as CamelAwsDdbFilterExpression or CamelAwsDdbProjectExpression. | Map | |
CamelAwsDdbKeySchema (DeleteTable DescribeTable UpdateTable) Constant: | The key schema of the table: the KeySchemaElement of the partition key, and of the sort key if the table has one. | List | |
CamelAwsDdbLastEvaluatedKey (Query Scan) Constant: | The primary key of the last item that Query or Scan read, or null when there are no more items to read. Set it as CamelAwsDdbStartKey to read the next page. | Map | |
CamelAwsDdbIsTruncated (Query Scan) Constant: | Whether Query or Scan stopped before reading all items, because of the limit of CamelAwsDdbLimit or of the 1 MB size of a response. If true, set CamelAwsDdbLastEvaluatedKey as CamelAwsDdbStartKey to read the next page. | Boolean | |
| Constant: | The maximum number of items that Query or Scan reads (Limit), before the filter is applied, so fewer items can be returned. DynamoDB also stops at 1 MB of data, with or without this header. | Integer | |
CamelAwsDdbOperation (producer) Constant: | The operation to perform. It replaces the operation option. Enum values:
| Ddb2Operations | |
CamelAwsDdbProvisionedThroughput (DeleteTable DescribeTable UpdateTable) Constant: | The provisioned throughput of the table: its read and write capacity units, and the times of their last increase and decrease. | ProvisionedThroughputDescription | |
CamelAwsDdbReadCapacity (UpdateTable DescribeTable) Constant: | ReadCapacityUnits property of this table. UpdateTable reads it as the read capacity to set, and DescribeTable sets it to the read capacity of the table: remove it before an UpdateTable that follows a DescribeTable, or the UpdateTable sets the capacity the DescribeTable read instead of the readCapacity option. | Long | |
CamelAwsDdbReturnValues (producer) Constant: | The attributes that PutItem, UpdateItem or DeleteItem return in CamelAwsDdbAttributes (ReturnValues): NONE, ALL_OLD, UPDATED_OLD, ALL_NEW or UPDATED_NEW. PutItem and DeleteItem accept only NONE and ALL_OLD. If not set, no attributes are returned. | String | |
CamelAwsDdbScannedCount (Scan) Constant: | The number of items that Scan read, before the filter was applied. It differs from CamelAwsDdbCount when a filter is set. | Integer | |
CamelAwsDdbScanIndexForward (producer) Constant: | Whether Query reads the items in ascending order of the sort key (true) or in descending order (false). If not set, DynamoDB reads them in ascending order. | Boolean | |
CamelAwsDdbScanFilter (producer) Constant: | The conditions that the items that Scan reads must meet to be returned, as a map of attribute name to Condition (the legacy ScanFilter parameter). DynamoDB rejects it in a request that also has an expression, such as CamelAwsDdbFilterExpression. | Map | |
CamelAwsDdbStartKey (producer) Constant: | The primary key of the item after which Query or Scan starts reading (ExclusiveStartKey): the CamelAwsDdbLastEvaluatedKey of the page before. | Map | |
CamelAwsDdbTableName (producer) Constant: | The name of the table that the operation works on, instead of the table of the endpoint. The batch, transaction and PartiQL operations do not use it. | String | |
CamelAwsDdbTableSize (DeleteTable DescribeTable UpdateTable) Constant: | The size of the table in bytes, which DynamoDB updates about every six hours. | Long | |
CamelAwsDdbTableStatus (DeleteTable DescribeTable UpdateTable) Constant: | The status of the table, such as CREATING, UPDATING, DELETING or ACTIVE. Enum values:
| TableStatus | |
CamelAwsDdbUpdateCondition (producer) Constant: | The conditions that the item must meet for PutItem, UpdateItem or DeleteItem to change it, as a map of attribute name to ExpectedAttributeValue (the legacy Expected parameter). If the item does not meet them, the operation fails with a ConditionalCheckFailedException. | Map | |
CamelAwsDdbUpdateValues (producer) Constant: | The changes that UpdateItem makes to the item, as a map of attribute name to AttributeValueUpdate with the new value and the action: PUT, ADD or DELETE (the legacy AttributeUpdates parameter). | Map | |
CamelAwsDdbUnprocessedKeys (BatchGetItems) Constant: | The keys that BatchGetItems did not read, for example because of throttling or of the size limit of a response, in the form of CamelAwsDdbBatchItems: send them in another BatchGetItems to read them. | Map | |
CamelAwsDdbWriteCapacity (UpdateTable DescribeTable) Constant: | WriteCapacityUnits property of this table. UpdateTable reads it as the write capacity to set, and DescribeTable sets it to the write capacity of the table: remove it before an UpdateTable that follows a DescribeTable, or the UpdateTable sets the capacity the DescribeTable read instead of the writeCapacity option. | Long | |
CamelAwsDdbStatement (ExecuteStatement) Constant: | The PartiQL statement that ExecuteStatement runs. It can have ? placeholders for the values of CamelAwsDdbStatementParameters. | String | |
CamelAwsDdbStatementParameters (ExecuteStatement) Constant: | The values of the ? placeholders of the PartiQL statement, in their order in the statement. | List | |
CamelAwsDdbBatchStatements (BatchExecuteStatement) Constant: | The list of PartiQL statements representing the batch to run. | List | |
CamelAwsDdbExecuteStatementItems (ExecuteStatement) Constant: | The items that the PartiQL statement read, each a map of attribute name to AttributeValue. It is one page of the result: see CamelAwsDdbNextToken. | List | |
CamelAwsDdbBatchStatementResponse (BatchExecuteStatement) Constant: | The response to each PartiQL statement in the batch. | List | |
CamelAwsDdbTransactWriteItems (TransactWriteItems) Constant: | The list of TransactWriteItem objects for a transactional write. | List | |
CamelAwsDdbTransactClientRequestToken (TransactWriteItems) Constant: | The client request token of TransactWriteItems, which makes the call idempotent: DynamoDB does not apply again a call with the same token that succeeded within the last 10 minutes. | String | |
CamelAwsDdbTransactWriteConsumedCapacity (TransactWriteItems) Constant: | The capacity that TransactWriteItems consumed. It is always an empty list, as the request does not ask DynamoDB for it (ReturnConsumedCapacity). | List | |
CamelAwsDdbTransactWriteItemCollectionMetrics (TransactWriteItems) Constant: | The item collection metrics of TransactWriteItems. It is always an empty map, as the request does not ask DynamoDB for them (ReturnItemCollectionMetrics). | Map | |
CamelAwsDdbTransactGetItems (TransactGetItems) Constant: | The list of TransactGetItem objects for a transactional read. | List | |
CamelAwsDdbTransactGetResponse (TransactGetItems) Constant: | The items that TransactGetItems read: an ItemResponse for each TransactGetItem of CamelAwsDdbTransactGetItems, in the same order. | List | |
CamelAwsDdbBatchWriteItems (BatchWriteItems) Constant: | A map of table names to lists of WriteRequest objects for batch writes. | Map | |
CamelAwsDdbBatchWriteUnprocessedItems (BatchWriteItems) Constant: | The write requests that BatchWriteItems did not process, for example because of throttling, in the form of CamelAwsDdbBatchWriteItems: send them in another BatchWriteItems to process them. | Map | |
CamelAwsDdbFilterExpression (Query Scan) Constant: | The filter expression (FilterExpression) that the items that Query or Scan reads must meet to be returned. DynamoDB rejects it in a request that also has a legacy parameter, such as the CamelAwsDdbKeyConditions of Query or CamelAwsDdbScanFilter. | String | |
CamelAwsDdbFilterExpressionAttributeNames (Query Scan) Constant: | The attribute names of the placeholders (#name) in the filter and projection expressions of Query or Scan, as a map of placeholder to attribute name (ExpressionAttributeNames). | Map | |
CamelAwsDdbFilterExpressionAttributeValues (Query Scan) Constant: | The values of the placeholders (:value) in the filter expression of Query or Scan, as a map of placeholder to AttributeValue (ExpressionAttributeValues). | Map | |
CamelAwsDdbProjectExpression (Query Scan) Constant: | The projection expression (ProjectionExpression) of Query or Scan: the attributes to read, separated by commas. If not set, all attributes are read. DynamoDB rejects it in a request that also has a legacy parameter, such as CamelAwsDdbAttributeNames or the CamelAwsDdbKeyConditions of Query. | String |
Message Body
The message body at each side of the AWS DynamoDB 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 |
| Not used: the operations take their input from headers, such as the item in CamelAwsDdbItem and the key in CamelAwsDdbKey as maps of the AttributeValue of the AWS SDK, or the PartiQL statement in CamelAwsDdbStatement. |
Producer output |
| Unchanged for every operation: the result is in headers, such as CamelAwsDdbAttributes for the item operations, CamelAwsDdbItems for Query and Scan, and CamelAwsDdbExecuteStatementItems for ExecuteStatement. |
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 DDB component options
You have to provide the amazonDDBClient in the Registry or your accessKey and secretKey to access the Amazon’s DynamoDB.
Usage
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
Advanced AmazonDynamoDB configuration
If you need more control over the AmazonDynamoDB instance configuration you can create your own instance and refer to it from the URI:
DynamoDbClient configuration and registry bindingDynamoDbClient client = DynamoDbClient.builder()
.region(Region.AP_SOUTHEAST_2)
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey)))
.build();
getCamelContext().getRegistry().bind("client", client);
from("direct:start")
.to("aws2-ddb://tableName?amazonDDBClient=#client"); The #client refers to a DynamoDbClient in the Registry.
Supported producer operations
-
BatchGetItems
-
BatchWriteItems
-
BatchExecuteStatement
-
DeleteItem
-
DeleteTable
-
DescribeTable
-
ExecuteStatement
-
GetItem
-
PutItem
-
Query
-
Scan
-
TransactGetItems
-
TransactWriteItems
-
UpdateItem
-
UpdateTable
Result headers that are also inputs
The operations put their results in headers and keep the body. A few of these headers are also read as input by a later aws2-ddb step of the same route:
-
DescribeTable sets
CamelAwsDdbReadCapacityandCamelAwsDdbWriteCapacityto the capacity of the table. A following UpdateTable reads them as the capacity to set, before thereadCapacityandwriteCapacityoptions, so remove them before that UpdateTable. -
ExecuteStatement sets
CamelAwsDdbNextTokento the token of the next page of the statement, and reads it as the token of the page to read. A loop can page through the results of a statement with it, but remove it before running another statement.
DescribeTable, DeleteTable and UpdateTable do not set the CamelAwsDdbTableName header, so the next step works on the table it is configured with.
- route:
from:
uri: direct:resize
steps:
- to:
uri: aws2-ddb:orders
parameters:
operation: DescribeTable
- log:
message: "The orders table reads ${header.CamelAwsDdbReadCapacity} units"
- removeHeader:
name: CamelAwsDdbReadCapacity
- removeHeader:
name: CamelAwsDdbWriteCapacity
- to:
uri: aws2-ddb:orders
parameters:
operation: UpdateTable
readCapacity: 10
writeCapacity: 10 JSON data type transformer
The aws2-ddb:application-json data type transformer turns a JSON body into the headers of PutItem, UpdateItem and DeleteItem. The JSON properties become the attributes of the item. The body can also have a top-level key property with the key attributes and a top-level item property with the item attributes, such as for UpdateItem.
The route chooses the operation with the CamelAwsDdbOperation header or the operation exchange property; the transformer then sets the headers of that operation. When the route sets neither, the transformer leaves the operation to the operation option of the endpoint, and sets the CamelAwsDdbItem, CamelAwsDdbKey and CamelAwsDdbUpdateValues headers.
The JSON body does not choose the operation: a body with a top-level operation property fails, unless the route sets that same operation.
- route:
from:
uri: direct:remove
steps:
- transformDataType:
toType: aws2-ddb:application-json
- to:
uri: aws2-ddb:orders
parameters:
operation: DeleteItem 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-ddb</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.
Examples
Producer Examples
In YAML, an operation that needs no AWS SDK objects is set with the operation option, such as DescribeTable. The other examples below build AttributeValue maps in Java.
- route:
from:
uri: direct:describe
steps:
- to:
uri: aws2-ddb:orders
parameters:
operation: DescribeTable
region: eu-west-1
accessKey: "{{aws.access-key}}"
secretKey: "{{aws.secret-key}}"
- log:
message: "Items in the orders table: ${header.CamelAwsDdbTableItemCount}" -
PutItem: this operation will create an entry into DynamoDB
AttributeValue builders and variable table nameMap<String, AttributeValue> attributeMap = new HashMap<>();
attributeMap.put("partitionKey", AttributeValue.builder().s("3000").build());
attributeMap.put("id", AttributeValue.builder().s("1001").build());
attributeMap.put("barcode", AttributeValue.builder().s("9002811220001").build());
from("direct:start")
.setHeader("CamelAwsDdbOperation", constant("PutItem"))
.setHeader("CamelAwsDdbConsistentRead", constant("true"))
.setHeader("CamelAwsDdbReturnValues", constant("ALL_OLD"))
.setHeader("CamelAwsDdbItem", constant(attributeMap))
.setHeader("CamelAwsDdbAttributeNames", constant(attributeMap.keySet()))
.to("aws2-ddb://" + tableName + "?amazonDDBClient=#client"); -
UpdateItem: this operation will update an entry into DynamoDB
AttributeValue and AttributeValueUpdate buildersMap<String, AttributeValueUpdate> attributeMap = new HashMap<>();
attributeMap.put("partitionKey", AttributeValueUpdate.builder().value(AttributeValue.builder().s("3000").build()).build());
attributeMap.put("sortKey", AttributeValueUpdate.builder().value(AttributeValue.builder().s("1001").build()).build());
attributeMap.put("borcode", AttributeValueUpdate.builder().value(AttributeValue.builder().s("900281122").build()).build());
Map<String, AttributeValue> keyMap = new HashMap<>();
keyMap.put("partitionKey", AttributeValue.builder().s("3000").build());
keyMap.put("sortKey", AttributeValue.builder().s("1001").build());
from("direct:start")
.setHeader("CamelAwsDdbOperation", constant("UpdateItem"))
.setHeader("CamelAwsDdbUpdateValues", constant(attributeMap))
.setHeader("CamelAwsDdbKey", constant(keyMap))
.to("aws2-ddb://" + tableName + "?amazonDDBClient=#client"); -
GetItem: this operation will retrieve an entry from DynamoDB
Processor with AWS SDK AttributeValue buildersfrom("direct:get")
.process(exchange -> {
final Map<String, AttributeValue> keyMap = new HashMap<>();
keyMap.put("table-key", AttributeValue.builder().s("1").build());
exchange.getIn().setHeader("CamelAwsDdbOperation", "GetItem");
exchange.getIn().setHeader("CamelAwsDdbAttributeNames", constant(List.of("table-key", "message")));
exchange.getIn().setHeader("CamelAwsDdbKey", keyMap);
})
.to("aws2-ddb://" + tableName + "?amazonDDBClient=#client&consistentRead=true"); -
DeleteItem: this operation will delete an entry from DynamoDB
Processor with AWS SDK AttributeValue buildersfrom("direct:delete")
.process(exchange -> {
final Map<String, AttributeValue> keyMap = new HashMap<>();
keyMap.put("table-key", AttributeValue.builder().s("1").build());
exchange.getIn().setHeader("CamelAwsDdbOperation", "DeleteItem");
exchange.getIn().setHeader("CamelAwsDdbKey", keyMap);
})
.to("aws2-ddb://" + tableName + "?amazonDDBClient=#client&consistentRead=true"); -
ExecuteStatement (PartiQL): this operation runs a PartiQL statement against DynamoDB
Processor with AWS SDK AttributeValue buildersfrom("direct:partiql")
.process(exchange -> {
exchange.getIn().setHeader("CamelAwsDdbOperation", "ExecuteStatement");
exchange.getIn().setHeader("CamelAwsDdbStatement",
"SELECT * FROM \"MyTable\" WHERE \"key\" = ?");
exchange.getIn().setHeader("CamelAwsDdbStatementParameters",
List.of(AttributeValue.builder().s("myKeyValue").build()));
exchange.getIn().setHeader("CamelAwsDdbConsistentRead", true);
})
.to("aws2-ddb://" + tableName + "?amazonDDBClient=#client"); -
BatchExecuteStatement (PartiQL batch): this operation runs multiple PartiQL statements in a batch
Processor with AWS SDK BatchStatementRequest buildersfrom("direct:batchPartiql")
.process(exchange -> {
exchange.getIn().setHeader("CamelAwsDdbOperation", "BatchExecuteStatement");
exchange.getIn().setHeader("CamelAwsDdbBatchStatements", List.of(
BatchStatementRequest.builder()
.statement("INSERT INTO \"MyTable\" VALUE {'key': 'k1', 'data': 'v1'}")
.build(),
BatchStatementRequest.builder()
.statement("INSERT INTO \"MyTable\" VALUE {'key': 'k2', 'data': 'v2'}")
.build()));
})
.to("aws2-ddb://" + tableName + "?amazonDDBClient=#client"); -
TransactWriteItems: this operation performs a transactional write across one or more tables
Processor with AWS SDK TransactWriteItem buildersMap<String, AttributeValue> item = new HashMap<>();
item.put("key", AttributeValue.builder().s("txKey").build());
item.put("data", AttributeValue.builder().s("txValue").build());
from("direct:transactWrite")
.process(exchange -> {
exchange.getIn().setHeader("CamelAwsDdbOperation", "TransactWriteItems");
exchange.getIn().setHeader("CamelAwsDdbTransactWriteItems", List.of(
TransactWriteItem.builder()
.put(Put.builder().tableName("MyTable").item(item).build())
.build()));
})
.to("aws2-ddb://" + tableName + "?amazonDDBClient=#client"); -
TransactGetItems: this operation performs a transactional read across one or more tables
Processor with AWS SDK TransactGetItem buildersMap<String, AttributeValue> key = new HashMap<>();
key.put("key", AttributeValue.builder().s("txKey").build());
from("direct:transactGet")
.process(exchange -> {
exchange.getIn().setHeader("CamelAwsDdbOperation", "TransactGetItems");
exchange.getIn().setHeader("CamelAwsDdbTransactGetItems", List.of(
TransactGetItem.builder()
.get(Get.builder().tableName("MyTable").key(key).build())
.build()));
})
.to("aws2-ddb://" + tableName + "?amazonDDBClient=#client"); -
BatchWriteItems: this operation puts or deletes multiple items in one or more tables in a single batch
WriteRequest and PutRequest buildersMap<String, AttributeValue> item1 = new HashMap<>();
item1.put("key", AttributeValue.builder().s("bk1").build());
item1.put("data", AttributeValue.builder().s("bv1").build());
Map<String, List<WriteRequest>> requestItems = new HashMap<>();
requestItems.put("MyTable", List.of(
WriteRequest.builder()
.putRequest(PutRequest.builder().item(item1).build())
.build()));
from("direct:batchWrite")
.process(exchange -> {
exchange.getIn().setHeader("CamelAwsDdbOperation", "BatchWriteItems");
exchange.getIn().setHeader("CamelAwsDdbBatchWriteItems", requestItems);
})
.to("aws2-ddb://" + tableName + "?amazonDDBClient=#client");