aws-appsync-community
aws-appsync-community copied to clipboard
DynamoDB Resolvers cannot know how many RCU/WCU an operation has consumed
The DynamoDB APIs accept the parameter "ReturnConsumedCapacity". When passed the result includes the consumed capacity units of the executed operation.
With that it is possible to associate "a cost" with a specific access pattern. This is ideal when trying to figure out what needs to be optimized in order to reduce the WCU/RCU.
When hitting DynamoDB directly from a Lambda function I always pass this parameter and then attach the result to an embedded CloudWatch metric. This is a recommendation comming directly from Rick Houlihan during one of his Re:Invent sessions.
A cannot do this with AppSync currently. There is not way to pass the "ReturnConsumedCapacity" to DynamoDB.
If it were possible to pass this parameter I would rely in a pipeline resolver in order to execute the DynamoDB operation and then notify to something else what the consumed units of the operation were.
Thinking about this a bit more, it would be ideal if AppSync pushed a metric to CloudWatch about the WCU/RCU consumed by each resolver by default.
I found a way to do this my self at the cost of some compute time.
If DynamoDB is hit using an HTTP function resolver instead of the native AppSync one (see here) then the WCU/RCU may be requested and logged in a subsequent function in a pipeline resolver