Reputation: 111
I have created and table in dynamodb (EU-WEST-1) and I have created a camel route to put a json payload into the table.
My route looks like this:
String dynamoDbEndpoint = String.format("aws-ddb://tablename?accessKey=%s&secretKey=RAW(%s)&tableName=tablename&amazonDdbEndpoint=dynamodb.eu-west-1.amazonaws.com",awsAccessKey,awsSecretKey);
from("direct:ipg-queue").to(dynamoDbEndpoint)
I get the error message:
com.amazonaws.AmazonServiceException: 1 validation error detected: Value null at 'item' failed to satisfy constraint: Member must not be null (Service: AmazonDynamoDB; Status Code: 400; Error Code: ValidationException; Request ID: 0AVSR54LRTOG3U0TTC5B1QO4KBVV4KQNSO5AEMVJF66Q9ASUAAJG)
An example payload is:
{"accountNumber":"123456789","customerName":"John Smith","id":"8422b9e0-739b-4d19-9291-037b68344068"}
Represented as a String.
I'm doing something stupid, but can't figure it out...
Upvotes: 0
Views: 1024
Reputation: 111
So it turns out I was being stupid. You just need to set the CamelAwdDbItem header in the exchange. I added the following process block to my route before the dynamo db endpoint and away I went...
.unmarshal()
.json(JsonLibrary.Gson, Map.class)
.process((Exchange exchange) -> {
Map body = (Map) exchange.getIn()
.getBody();
Map<String, AttributeValue> newBody = new HashMap();
for(Object key : body.keySet()) {
newBody.put(key.toString(), new AttributeValue(body.get(key).toString()));
}
exchange.getIn().setHeader("CamelAwsDdbItem", newBody);
})
I also put &operation=PutItem
onto the end of the endpoint definition.
Upvotes: 1