Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"list indices must be integers or slices, not str" ERROR

For some reason, I keep getting this error from AWS Lambda:

{
  "errorMessage": "list indices must be integers or slices, not str",
  "errorType": "TypeError",
  "stackTrace": [
    "  File \"/var/task/python.py\", line 25, in lambda_handler\n    metricName = event['detail']['configuration']['metrics']['metricStat']['metric']['name']\n"
  ]
}

The following part is the JSON part for what I am trying to reference to:

"configuration": {
      "metrics": [
        {
          "id": "ajdhflksdf4",
          "metricStat": {
            "metric": {
              "namespace": "AWS/RDS",
              "name": "CPUUtilization",
              "dimensions": {
                "DBInstanceIdentifier": "123456-rds-tester"
              }
            },
            "period": 60,
            "stat": "Average"
          },`
          "returnData": "True"
        }
      ],
      "description": "This metric monitors rds cpu utilization"
    }

I want to reference the name in the metric part and all of that is under the key ‘detail’. I was expecting to receive "CPUUtilization" for metricName

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The value of the key metrics is a list. You should access ...['metrics'][0]['metricStat']... instead of ...['metrics']['metricStat']..., as the sub-dictionary you wish to access is stored in the 0th index of the list.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading