Making your computer translate Amazon IAM Policies for you
Every time I write or read an AWS policy, I end up reading these same Docs here, because I can never remember what the resource or action means. Well no more! I want my computer to just tell me and Unix say is here to save me!
If you have policy in a file called policy.json with the following:
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::example_bucket"
}
}
Then heres a quick Python script parsing that file, and then reading it back to you:
from os import system
import json
system("clear")
print("\n\033[36;1mPolicy to Speech Translater\033[0m\n")
policy = open("policy.json").read()
print(policy)
parsed_policy = json.loads(policy)["Statement"]
effect = parsed_policy["Effect"]
action = parsed_policy["Action"]
resource = parsed_policy["Resource"]
system("say -v Cellos {effect} the holder of this policy to call these {action} on the these resources: {resource}".
format(effect=effect, action=action, resource=resource))
Make sure you have the Cellos user downloaded in your Accessibility > Speech settings.
If not you can just eliminate the user option.
system("say {effect} the holder of this policy to call these {action} on the these resources: {resource}".
format(effect=effect, action=action, resource=resource))
I want to improve this to learn more and have some fun with Text to Speech.
Possible improvements I would like to make:
- Create an SSML document after parsing the policy json
- Parse the actions and resources to read them in a more human friendly format
- Handle multiple actions and resources better
- Handle multiple policies
- Be able to pull policies from AWS with the AWS CLI
- Use AWS Polly