Extract key:pair from an object having a dynamic key

terms = json.loads(response['PriceList'][0])['terms']
print(f"Terms: {terms}")

I can’t seem to extract the pricePerUnit because of the dynamic key HY3BZPP2B6K8MSJF.JRTCKXETXF

Terms: {'OnDemand': {'HY3BZPP2B6K8MSJF.JRTCKXETXF': {'priceDimensions': {'HY3BZPP2B6K8MSJF.JRTCKXETXF.6YS6EN2CT7': {'unit': 'GB-Mo', 'endRange': 'Inf', 'description': '$0.10 per GB-month of General Purpose SSD (gp2) provisioned storage - US East (Northern Virginia)', 'appliesTo': [], 'rateCode': 'HY3BZPP2B6K8MSJF.JRTCKXETXF.6YS6EN2CT7', 'beginRange': '0', 'pricePerUnit': {'USD': '0.1000000000'}}}, 'sku': 'HY3BZPP2B6K8MSJF', 'effectiveDate': '2023-04-01T00:00:00Z', 'offerTermCode': 'JRTCKXETXF', 'termAttributes': {}}}}

You can iterate over the keys or keys/values of a dict.

from typing import Any, Dict
on_demand: Dict[str, Any] = terms["OnDemand"]

# Iterating over keys implicit
for key in on_demand:
  ...

# Iterating over keys explicit
for key in on_demand.keys():
  ...

# Iterating over keys and values:
for key, value in on_demand.items():
  ...

In any way you’re going to have the dinamic key populated on the key variable