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
It’s a list that contains a dictionary, so you would need to use:
That will return the first element of the list (in your example, there is only one) and then the
WindowId
element of that dictionary.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.
That shoud be enough.