How Do You Write a JSON File to Extract the Value of a Given Key in a JSON File?

Problem scenario
You want to print the value of a given non-nested key in a JSON value. How can Python help you achieve this?

Solution
Here is an illustrative example. Create a file called reader.py with the following lines of code:

import json
with open(“second.json”, “r”) as reading_content:
i = reading_content.read()
j = json.loads(i)
print(j[“bird”])

Have the JSON file look like this:

cat first.json

{“bird”: {“name”: “singy”,  » Read more..

What Do You Do If CloudWatch Metrics Are Not Showing Up in the Dashboard?

Problem scenario
You used a .json file and the AWS CLI to configure customized metrics. When you go to the GUI you do not see the graphs. The commands that were run with the .json file completed without errors or problems. How do you get the web console to show the metrics you configured for various AWS components?

Possible Solution #1
CloudWatch metrics are not all necessarily graphed.

 » Read more..

How Do You Troubleshoot “The filter VolumeId” is invalid?

Problem scenario
You run an aws ec2 command and you get use the –filters flag with Name=VolumeId (consistent with the casing that you see in other AWS CLI contexts). You receive a message about “the filter VolumeId” being invalid. What should you do?

Solution
Use “volume-id” instead of “VolumeId”.

In general we find that the syntax of the name itself,

 » Read more..

How Do You Troubleshoot the Message “jq: error…Cannot iterate over null”?

Problem scenario
You are running a jq command (e.g., piping output to jq). You receive message “jq: error…Cannot iterate over null.” What should you do?

Solution
Change the word “Parameters” to “Parameter”. By omitting an “s” from “Parameters”, the error may go away.

Verify there is output. Try running the command without the “jq” utility if possible. This error can happen if there is no output to parse.

 » Read more..

How Do You Troubleshoot the Ansible Message “ERROR! the field hosts is required but was not set”?

Problem scenario
You run an ansible-playbook command, but you get “ERROR! the field hosts is required but was not set”. What should you do?

Solution
Find the hyphens beneath the top “- name” stanza. Eliminate them. For example, if your playbook looks like this:

– name: Foobar
hosts: localhost
– vars:
goodone: “blahblah”
-tasks:

Make it look like this:

– name: Foobar
hosts: localhost
vars:
goodone: “blahblah”
tasks:

Now re-run it.

 » Read more..

How Do You Troubleshoot the Ansible Error ‘”hadoop_env” is undefined’?

Problem scenario
You try to run a playbook. But you get a message like this: ‘fatal: … “AnsibleUndefinedVariable” ‘hadoop_env’ is undefined’. What should you do?

Root cause: a variable you defined (e.g., in a playbook or role) is not getting assigned when you run the playbook.

Possible solution #1
Find the vars directory or create it.

 » Read more..

How Do You Use the AWS CLI to View the Targets of Routes in Route Tables in a VPC?

Problem scenario
You have a VPC with route tables. You want to search the targets to find a given value. What should you do?

Solution
As of early 2020, the output of aws describe-route-tables –filters –route-table-id abcd1234 –region us-west-2 will not include the word “target”. The value of target in the JSON output will be the ID of the given target.

 » Read more..

How Do You Troubleshoot the Errors “Expecting ‘,’ delimiter: line …column” or “No JSON object could be decoded”?

Problem scenario
You are trying to run a command that consumes a JSON file. You get an error such as “Expecting ‘,’ delimiter: line …column” or “No JSON object could be decoded”. What do you do?

Possible Solution #1
You may have an extra closing brace that you need to eliminate.

Possible Solution #2
Use https://jsonlint.com

 » Read more..

How Do You Troubleshoot the AWS CLI Command “An error occurred (AccessDeniedException) when calling the ListClusters operation”?

Problem scenario
You run this command aws eks list-clusters, but you get this message:

“An error occurred (AccessDeniedException) when calling the ListClusters operation: User: arn:aws:iam::12345678910:user/jdoe is not authorized to perform: eks:ListClusters on resource: arn:aws:eks:us-west-1:12345678910:cluster/*”

What should you do?

Solution
1. Go to the AWS Console and log in.
2. Go to IAM -> Users
3.

 » Read more..

How Do You Troubleshoot the Python Error “json.decoder.JSONDecode..”Expecting property name enclosed in double quotes…”?

Problem scenario
You are running a Python program that uses “import json”. You get this error: “json.decoder.JSONDecode..”Expecting property name enclosed in double quotes…” You are not allowed to use bson, but you can use other Python packages. What should you do?

Solution
This solution only works if you can eliminate single quotes in the content to be serialized (or translated into JSON).

 » Read more..