skip to Main Content

I have this lambda function

def lambda_handler(event, context):
    response = client.describe_maintenance_windows(
Filters=[
    {
        'Key': 'Name',
        'Values': [
            'test',
        ]
    },
],
)
MWId = response["WindowIdentities"]
return(MWId)

I got below response Response structure

[
  {
    "WindowId": "mw-0154acefa2151234",
    "Name": "test",
    "Enabled": true,
    "Duration": 4,
    "Cutoff": 0,
    "Schedule": "cron(0 0 11 ? * SUN#4 *)",
    "NextExecutionTime": "2024-08-25T11:00Z"
  }
] 

How do I get the value of WindowId so I can pass it to a variable? I tried below but I am getting "errorMessage": "’list’ object is not callable"

mwidvalue = MWId("WindowId")

2

Answers


  1. It’s a list that contains a dictionary, so you would need to use:

    mwidvalue = MWId[0]["WindowId"]
    

    That will return the first element of the list (in your example, there is only one) and then the WindowId element of that dictionary.

    Login or Signup to reply.
  2. As the error you mentioned says, you are working with a list. For that reason, you need to get the element of the list that you want to work on it and then do whatever action you want to do.

    In this case, the element inside of the list is a dictionary, so you can use get methods to obtain the element.

    MWId[0].get("WindowId")
    

    That shoud be enough.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search