0

Actually, I am creating several utilities to deal with AWS CLI responses, which responds with json. My whole scripts ecosystem are based in Python, and usually I create tiny utilities that fetches the json data and parses to readable/organized data.

But I have noticed that I am taking so much time to creates scripts, besides hiding the data structure responses, something that may also be useful.

A much more interesting alternative would create a script that just receives the json data from aws cli and with a map as argument, filters down the information to what I need. And I pretend do this by a simple shell redirect (pipe).

Right now, I can do something like that in Node.js script. Following illustrates exactly how I would like to operates in Python: enter image description here

Unless someone says that does not have a way to redirect shell command output to a python script, I prefer not to maintain just this piece of code in a different language than all the others.

How do I do the shell output redirection to a python script?

1 Answer 1

1

You could read sys.stdin in Python. My understanding of the above javascript code is translates to this in Python:

import sys
import json

object_data = json.loads(sys.stdin.read())
print(object_data['description'])

However do note that the AWS API has a Python SDK, so you probably don't have to pipe around these JSON outputs at all.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.