1

A newbie here. I'm trying to workout how I should go about extracting some specific values from a json output produced upon executing a particular boto3 method. Below is the code that works;

import json
import boto3

def lambda_handler(event, context):

    client = boto3.client('apigateway')
    response = client.get_usage_plans()['items']
    return response

Above gives me the below output as expected.

Response:
[
  {
    "id": "p90xvt",
    "name": "Basic",
    "apiStages": [
      {
        "apiId": "g1gckiw2cj",
        "stage": "prod"
      }
    ],
    "quota": {
      "limit": 10,
      "offset": 0,
      "period": "DAY"
    }
  },
  {
    "id": "rt9k2q",
    "name": "Prem",
    "apiStages": [
      {
        "apiId": "g1gckiw2cj",
        "stage": "prod"
      }
    ],
    "quota": {
      "limit": 10,
      "offset": 0,
      "period": "DAY"
    }
  }
]

Request ID:
"4aa80ca1-c48d-11e8-95cf-f59e9444b72c"

Function Logs:
START RequestId: 4aa80ca1-c48d-11e8-95cf-f59e9444b72c Version: $LATEST
END RequestId: 4aa80ca1-c48d-11e8-95cf-f59e9444b72c
REPORT RequestId: 4aa80ca1-c48d-11e8-95cf-f59e9444b72c  Duration: 631.18 ms Billed Duration: 700 ms     Memory Size: 128 MB Max Memory Used: 31 MB  

What I'm struggling to understand is that how to extract some specific key:values from the output? Say If I want to print YES if the limit of a quota belongs to a specific id(i.e:"p90xvt") equals to 10? Mind you I need to cover all ids.

Really appreciate your help on this people. Many thanks in advance. -B

1
  • Sorry, it's not clear what you're trying to do. You have a list of dicts, so you can access the values like this: d=response[0]; print(d["id"], d["quota"]["limit"]) Commented Sep 30, 2018 at 9:30

1 Answer 1

1
 for field in response:
        if field['quota']['limit']==10:
            print (field['id'])
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.