I have the a table in DynamoDB called "environments_protection" and it looks like so:
{
"environment_name": {
"S": "qa-devops-1"
},
"asg_c": {
"M": {
"desired": {
"N": "4"
},
"max": {
"N": "4"
},
"min": {
"N": "1"
},
"context": {
"S": "test-context"
}
}
},
"cp_sp_svc": {
"M": {
"desired": {
"N": "2"
},
"context": {
"S": "test-context"
}
}
},
"issuer": {
"S": "itai"
},
"protected": {
"BOOL": false
},
"services_task_count": {
"L": [
{
"M": {
"desired": {
"N": "3"
},
"name": {
"S": "service1"
},
"context": {
"S": "test-context"
}
}
},
{
"M": {
"desired": {
"N": "1"
},
"name": {
"S": "service2"
},
"context": {
"S": "test-context"
}
}
},
{
"M": {
"desired": {
"N": "2"
},
"name": {
"S": "service3"
},
"context": {
"S": "test-context"
}
}
}
]
}
}
I'm trying to update service1 "desired" value to 5 using boto3.
Here's the relevant part of my code:
tableName = 'environments_protection'
response = table.get_item(Key={'environment_name': 'qa-devops-1'})
item = response['Item']
for elem in item['services_task_count']:
name = elem['name']
desired = elem['desired']
print(f"service name: {name}, desired: {desired}")
table.update_item(
Key={'environment_name': 'qa-devops-1'},
UpdateExpression=f"set desired = :x",
ExpressionAttributeValues={
':x': '5',
},
ReturnValues="UPDATED_NEW"
)
I know i'm missing the part that aims to change only service1 but I didn't find a way to do it.
I've followed the answers in this SO question but couldn't get the update to work.
How do I change my update_item function so it updates the right value?