-
Notifications
You must be signed in to change notification settings - Fork 662
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
marshal dynamodb results directly to JSON #134
Comments
Thanks for posting this feature request, @jonsmirl. Are you looking for the DynamoDB API calls to return a JSON string of the result directly, instead of the AttributeValues that are normally returned?Or are you looking for a utility that allows you to convert AttributeValue collections to the DynamoDB JSON representation? |
Does it work like this? http request goes off to DynamoDB and the results come back as JSON. Two optimizations seem possible
Also, parallel optimizations can be applied to writing data to DynamoDB. My incoming data is already in a JSON string, it would be great if I could simply pass that string into DynamoDB unchanged. My Go code is used to validate the user and to ensure they don't read/write from unauthorized places (I use CognitoIDs). The Go code doesn't touch the data in either direction. On the plus side I am converting these functions from Javascript (where they run 500-1000ms) over to Go which so far is running in the 200-300ms range. Getting rid of pointless shuffling of the data by Go might reduce my run-time down to 100ms. |
A function that would convert AttributeValue collections directly to a valid JSON string would be very handy. The JSON strings can be passed to all manner of library functions and other things -- without the need to pass thru Go specific struct definitions. My current need is simply to pass the retrieved data via a .JSON file -- the Go code never uses the content of the object at all. |
Thanks for the update @jonsmirl and @warrenstephens. Since the AttributeValue type is used within as a field within a JSON document, there is not a clean way to inject the AttributeValue as a JSON string/byte slice. Since we have a good understanding of the use case we can use this issue to track design proposals for this feature. There are a few ways I think this could be implemented with varying levels of "completeness" Ideas:1.) Add custom member to AttributeValueAdding a custom member, (e.g. Reading a response from DynamoDB, the This would be limited to AttributeValue type only, does not cover 2.) Add Additional byte slice API input/output parametersFor every API input/output that contains an The second option seems to be more of a sledge hammer to the problem, and it would be better to find a cleaner, more concise solution to this issue. |
Any updates on this issue? Approach #1 would greatly increase the performance of some applications I maintain. |
I'm also interested on the resolution of this enhancement. thank you. |
Any updates on this? I'm interested as well. |
I think a better example would be that json.Unmarshal of DynamoDB JSON would result in a map[string]types.AttributeValue because then one can use attributevalue.UnmarshalMap will get you your go type which can be json.Marshaled to normal JSON. I had to port dynamodbattribute from v1 SDK so I could get my go type from a DynamoDB Streams Event |
Hi all, I have discussed with the team, and we are planning to implement this. However, there is no timeline for this yet, I will comment if we have any update. |
There is already a function aws-sdk-go-v2/service/dynamodb/serializers.go Line 3374 in 98519e6
This can be copied into a public function. This should only take a couple of days to implement. |
This is a critical path feature that should already be supported. |
I would love to see some traction on this, but want to revise the ideas proposed earlier: My use case would prefer to not allocate everything in memory, but rather accept an
Those honestly appear to be the only blockers. I may just fork the repo and make those changes to unblock myself |
Respectfully, while the Writer interface is commonly used for a lot of things in go and that is kind of a golang thing, I don't believe that that alone should block this. First version doing allocations is fine, as long as the interface allows updates and optimizations later. If the initial requirement is that it support the Write interface to cll Write(*), then provide an option for that, but don't focus too much on optimization prematurely. It's better to get the interfaces correct, first. The initial implementation could be as simple as a strings.Builder consuming the write of the json to return the result. Separation of concerns is also an issue, and I don't believe that overloading concerns is going to be useful here. It might be better for backwards compatibility to have additional API's. |
Chiming in on this given the amount of attention/upvotes it's received in the past. As an FYI, jasdel@ and vudh1@ are no longer on the project, so the only context I have is what I can read here. I'd like to highlight a few very salient points from the discussion so far-
Given those points I think the way I'd like us to support this is through something entirely generic like the following: // WithHijackToReader skips deserialization and instead passes the response
// body to the provided reader.
func WithHijackToReader(r *io.ReadCloser) func(*middleware.Stack) error
// WithHijackToWriter skips deserialization and instead directly copies
// the contents of the response bodyto the provided writer.
func WithHijackToWriter(r io.Writer) func(*middleware.Stack) error
// example
var body io.ReadCloser
svc.Scan(context.Background(), &dynamodb.ScanInput{
// ...
}, dynamodb.WithAPIOptions(WithHijackToReader(&body))) These would exist as escape hatches which you could apply to any SDK operation. A crude version of this is actually entirely possible today. You can just blow out the func withHijackResponseBody(body *io.ReadCloser) func(*dynamodb.Options) {
return func(o *dynamodb.Options) {
o.APIOptions = append(o.APIOptions, func(s *middleware.Stack) error {
s.Deserialize.Clear()
// implementation of hijackResponseBody is omitted but it essentially just plumbs the body
// from out.RawResponse back to the iface ptr
return s.Deserialize.Add(&hijackResponseBody{body: body}, middleware.After)
})
}
} I can't necessarily sanction this as a workaround at this time- will get into it below, but if you do this today you're liable to bypass a set of behavior that you really shouldn't. There are definitely a few things as-written that prevent us from supporting this today:
Some of the points above could probably be written off as risks/tradeoffs accepted due to the (imo) advanced nature of this use case, others would have to be addressed before we implement. |
Hi all, We have recently discussed this as a team. At this time we don't plan on supporting this functionality as it's out of the SDK's scope. Ran~ |
This issue is now closed. Comments on closed issues are hard for our team to see. |
When writing lambda functions that query dynamodb I often simply send this data back to the lamdba caller as a JSON result. I would find it useful to have marshalling functions that go directly from the dynamodb result to json (in addition to the existing ones). This would optionally let me skip a lot of pointless conversions and memory allocations building the intermediate go structure which is promptly destroyed one line later in my code. Note, I'm not bringing back just a single item, usually it is an array of several thousand items.
The text was updated successfully, but these errors were encountered: