4

I'm trying to run a command with AWS CLI with query. The command could be something simple like aws s3api list-buckets --query 'sum(Versions[*].Size)'

However, occasionally, some values can return null. In the example above, size can be null when there is nothing and the command will return the following error:

In function sum(), invalid type for value: None, expected one of: ['array-number'], received: "null"

How can I give it a default value? If the actual value is null, I would like to set it to 0 so that there is some value in the result instead of an error.

Carven
  • 14,988
  • 29
  • 118
  • 161

1 Answers1

6

Based on the comments.

The solution was to use:

aws s3api list-buckets --query 'sum(Versions[*].Size || [`0`])'
Marcin
  • 215,873
  • 14
  • 235
  • 294