boto3 python lambda从json响应中提取值

时间:2018-09-30 09:04:37

标签: python boto3

一个新手。我正在尝试锻炼应该如何从执行特定boto3方法时产生的json输出中提取一些特定值。下面是有效的代码;

import json
import boto3

def lambda_handler(event, context):

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

上面给出了我预期的以下输出。

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  

我想了解的是如何从输出中提取一些特定的key:values?说,如果配额限制属于特定ID(即“ p90xvt”)等于10,是否要打印YES?请注意,我需要掩盖所有ID。

非常感谢您对这个人的帮助。 提前谢谢了。 -B

1 个答案:

答案 0 :(得分:0)

 for field in response:
        if field['quota']['limit']==10:
            print (field['id'])