Hello, I’m working on learning Rust, and I thought I’d try and use it for a problem that I had at work a few days ago. Background, for anyone interested:
I am a developer, and our company has a system where we don’t have credentials for our production AWS environment. We have to get our operations people to do anything that involves accessing production AWS. I needed to get the results of a few dozen AWS SWF executions to debug an issue, so I wrote a short Python script to get the info and save it to a JSON file for my analysis. It should have been simple, but the particular ops engineer had some issues with his Python install and it ended up taking a while to get the dependencies sorted out. I thought it would be nice if I could do the same task in a compiled language that would not have any dependencies on the system it was installed on to avoid this, so I decided to try to do the same thing in Rust.
The task seems simple, in that I just need to get a few dozen responses to AWS SWF calls and write the full body as JSON to a file. There seems to be a handy rusoto_swf crate that will set up AWS credentials and make all of the required requests for me. Great! Only problem is that the response object I need, WorkflowExecutionDetail, implements Deserialize, but not Serialize. It’s handy that it comes back as a nice Rust struct, but I just want to write the JSON back out to a file.
It seems I can’t make any changes to the crate’s struct, or to the type returned by the crate’s method, so the only way I could figure out to make it work was to copy the code for those particular calls into my app and make the changes there. I was able to modify the code to parse the response as a generic
serde_json::Value, which allowed me to combine it with the rest of the responses and output back out as JSON text. This all seems pretty awkward though, could there be any easier way to do this?
I did also try outputting the data structures using the debug output. That does produce output, but it isn’t JSON, so it’s much harder to search through with other tools.