- Newest
- Most votes
- Most comments
RequestIds are generated by the service, not the client side SDK, this is why it is being overwritten.
Curious as to why you need to use a custom requestId?
Hey thanks for your reply, I'm trying this but not working for me
AwsRequestOverrideConfiguration awsRequestOverrideConfiguration = AwsRequestOverrideConfiguration.builder()
.putHeader("aws-request-id", "123345")
.build();
PutItemRequest putItemRequest = PutItemRequest.builder()
.item(stringAttributeValueMap)
.tableName(getTableName())
.overrideConfiguration(awsRequestOverrideConfiguration)
//.overrideConfiguration(s -> s.putHeader("x-amz-request-id", awsRequestId))
.returnValuesOnConditionCheckFailure(ReturnValuesOnConditionCheckFailure.ALL_OLD)
.conditionExpression(expression.expression())
.build();
try {
dbclient.putItem(putItemRequest);
} catch (ConditionalCheckFailedException exception) {
exception.requestId() // not what i've sent
throw new RecordAlreadyExists("value %s for field %s already exists ".formatted("uniqueKeyAttributeName", "uniqueKeyAttributeName"),
exception);
}
Yes, it is possible to pass a custom AWS request ID when using the DynamoDB Java SDK (v2.29.17). You can achieve this by using the request override configuration feature provided by the SDK.
To set a custom AWS request ID, you can use the AwsRequestOverrideConfiguration
class. This class allows you to add custom headers to your request, including the 'aws-request-id' header.
Here's how you can do it:
- Create an
AwsRequestOverrideConfiguration
object with your custom request ID. - Add this configuration to your DynamoDB request using the
overrideConfiguration()
method.
For example, if you're using the ExecuteStatementRequest.Builder
, you can do something like this:
String customRequestId = "your-custom-request-id"; AwsRequestOverrideConfiguration overrideConfig = AwsRequestOverrideConfiguration.builder() .putHeader("aws-request-id", customRequestId) .build(); ExecuteStatementRequest request = ExecuteStatementRequest.builder() .statement("Your PartiQL statement") .overrideConfiguration(overrideConfig) .build();
This approach allows you to set a custom AWS request ID for your DynamoDB operations. However, it's important to note that while you can set this custom ID, the service may still generate its own request ID for internal tracking purposes.
Remember that each request includes a request ID by default, which can be useful for diagnosing issues with AWS Support. If you're overriding this ID, make sure to keep track of both your custom ID and the one returned by AWS for comprehensive request tracking.
Sources
DescribeImportRequest.Builder (AWS SDK for Java - 2.21.29)
ExecuteStatementRequest.Builder (AWS SDK for Java - 2.21.29)
Programming DynamoDB with the AWS SDK for Java 2.x - Amazon DynamoDB
Relevant content
- asked a year ago
- asked 5 months ago
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 4 years ago
- AWS OFFICIALUpdated 3 years ago
I dont want my record to be overridden hence i'm catching the exception, but when the request times out (After the leader gets the record) the client automatically retries and the second attempt fails with this exception. My idea is to set the request-id to know when this happens as the request-id will be different
You shouldn't try it like this. Try one of these methods: