Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the cost for using DynamoDB Stream Kinesis Adapter + Kinesis Client Library to read DDB Stream #47

Open
RuiZhang2 opened this issue Oct 25, 2021 · 2 comments

Comments

@RuiZhang2
Copy link

RuiZhang2 commented Oct 25, 2021

Quote from DDB Pricing for On-Demand Capacity:
DynamoDB charges for reading data from DynamoDB Streams in read request units. Each GetRecords API call is billed as a streams read request unit and returns up to 1 MB of data from DynamoDB Streams. Streams read request units are unique from read requests on your DynamoDB table. You are not charged for GetRecords API calls invoked by AWS Lambda as part of DynamoDB triggers. You also are not charged for GetRecords API calls invoked by DynamoDB global tables.

It seems like 1 GetRecords API = 1 read request unit. Since after switching to adapter and KCL library, there is no GetRecords API call at all. How can we know the number of read units we make? Can you share more details how to calculate the cost on README?

@RuiZhang2 RuiZhang2 changed the title What is the charge for using DynamoDB Stream Kinesis Adapter + Kinesis Client Library to read DDB Stream What is the cost for using DynamoDB Stream Kinesis Adapter + Kinesis Client Library to read DDB Stream Oct 25, 2021
@pingleig
Copy link

The adapter still call GetRecords under the hood (see code snippet at the end). There is CloudWatch metrics on GetRecords calls, in console you can find it by click table name and the monitoring tab.

If you want to avoid calling GetRecord you should use https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/kds.html in this case, you will use KCL directly without this adapter because you are calling Kinesis API directly. Changes in DynamoDB table are sent to Kinesis by DynamoDB service, though the order guarantee in DDB stream is not preserved in Kinesis stream and the cost model is different.

/**
* @param getRecordsRequest Container for the necessary parameters to execute the GetRecords service method on DynamoDB Streams.
* @return The response from the GetRecords service method, adapted for use with the AmazonKinesis model.
*/
@Override
public GetRecordsResult getRecords(GetRecordsRequest getRecordsRequest) {
if (getRecordsRequest.getLimit() != null && getRecordsRequest.getLimit() > GET_RECORDS_LIMIT) {
getRecordsRequest.setLimit(GET_RECORDS_LIMIT);
}
GetRecordsRequestAdapter requestAdapter = new GetRecordsRequestAdapter(getRecordsRequest);
requestCache.addEntry(getRecordsRequest, requestAdapter);
try {
com.amazonaws.services.dynamodbv2.model.GetRecordsResult result = internalClient.getRecords(requestAdapter);
List<Record> records = result.getRecords();
if (records != null && !records.isEmpty()) {
final int lastIndex = result.getRecords().size() - 1;
final StreamRecord lastStreamRecord = result.getRecords().get(lastIndex).getDynamodb();
final double lastApproximateCreationTimestamp = lastStreamRecord.getApproximateCreationDateTime().getTime();
final double millisBehindLatest = Math.max(System.currentTimeMillis() - lastApproximateCreationTimestamp, 0);
IMetricsScope scope = MetricsHelper.getMetricsScope();
scope.addData(MILLIS_BEHIND_LATEST_METRIC, millisBehindLatest, StandardUnit.Milliseconds, MetricsLevel.SUMMARY);
}
if (result != null && result.getNextShardIterator() == null && result.getSdkResponseMetadata() != null) {
LOG.info("RequestId for getRecords which resulted in ShardEnd: " + result.getSdkResponseMetadata().getRequestId());
}
return new GetRecordsResultAdapter(result, generateRecordBytes);
} catch (AmazonServiceException e) {
throw AmazonServiceExceptionTransformer.transformDynamoDBStreamsToKinesisGetRecords(e, skipRecordsBehavior);
}
}

@amdhing
Copy link

amdhing commented Jul 27, 2022

The adapter makes GetRecords calls. You can identify the number of GetRecords calls made by your consumer applications towards a DynamoDB Stream by checking the SampleCount statistic for SuccessfulRequestLatency CloudWatch metric associated for the DynamoDB Stream.

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/metrics-dimensions.html#SuccessfulRequestLatency

It may not be possible to identify calls made on a per consumer application level in-case multiple distinct consumer applications are consuming from the same stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants