Here is my code
KinesisClient kinesisClient = KinesisClient.builder().build();
PutRecordRequest putRecordRequest = new PutRecordRequest();
putRecordRequest.setStreamName("stream-name");
putRecordRequest.setPartitionKey("SomeString-" + UUID.randomUUID());
putRecordRequest.setData(ByteBuffer.wrap(data));
PutRecordResponse putRecordResponse = kinesisClient.putRecord(putRecordRequest);
For some strange reason it’s saying it can’t resolve the putRecord(PutRecordRequest)
method even though it’s clearly there when I look at the decompiled jar file. It even autocompletes that method when I start to type it.
What could be going wrong here?
2
Answers
I figured it out. For some reason I was using
com.amazonaws.services.kinesis.model
andsoftware.amazon.awssdk.services.kinesis.model
in my project. I was using theKinesisClient
from one package and thePutRecordRequest
from the other package.To work with AWS Services and Java, best pratice is to use AWS SDK for Java V2. The package software.amazon.awssdk.services.kinesis.model is V2. You are using V1, which is not recommended as specified on this AWS Page:
AWS SDK Code Examples
The full Java V2 code example for this operation is:
You can find this AWS SDK for Java V2 example in the AWS Code Lib here:
Kinesis examples using SDK for Java 2.x
If you prefer using Github, here is where all AWS Java V2 code examples are located:
https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2