pmiranda
pmiranda

Reputation: 8420

AWS Scan on DynamoDB condition-expression option

I'm trying to scan item where some field called reason be a String with:

aws dynamodb scan --table-name my_table --condition-expression "attribute_type(reason, :v_sub)" --expression-attribute-values file://expression-attribute-values.json

expression-attribute-values.json is:

{
    ":v_sub":{"S":"SS"}
}

I took the example from: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ConditionExpressions.html but I'm getting this error:

enter image description here

any hint?

Upvotes: 1

Views: 871

Answers (1)

Miguel Trejo
Miguel Trejo

Reputation: 6667

This is because the scan operation does not accept condition-expression as parameter, avaible options are

--table-name <value>
          [--index-name <value>]
          [--attributes-to-get <value>]
          [--select <value>]
          [--scan-filter <value>]
          [--conditional-operator <value>]
          [--return-consumed-capacity <value>]
          [--total-segments <value>]
          [--segment <value>]
          [--projection-expression <value>]
          [--filter-expression <value>]
          [--expression-attribute-names <value>]
          [--expression-attribute-values <value>]
          [--consistent-read | --no-consistent-read]
          [--cli-input-json | --cli-input-yaml]
          [--starting-token <value>]
          [--page-size <value>]
          [--max-items <value>]
          [--generate-cli-skeleton <value>]
          [--cli-auto-prompt <value>]

However the put-item operation does accept a condition-expression and --expression-attribute-values parameters, see complete list below. Additionally, notice that a condition-expression is "A condition that must be satisfied in order for a conditional PutItem operation to succeed"

  put-item
          --table-name <value>
          --item <value>
          [--expected <value>]
          [--return-values <value>]
          [--return-consumed-capacity <value>]
          [--return-item-collection-metrics <value>]
          [--conditional-operator <value>]
          [--condition-expression <value>]
          [--expression-attribute-names <value>]
          [--expression-attribute-values <value>]
          [--cli-input-json | --cli-input-yaml]
          [--generate-cli-skeleton <value>]
          [--cli-auto-prompt <value>]

By checking the docs, only Condition Expressions accept functions like attribute_type. See Syntax for Conditions Expressions and Condition Expressions Examples

References

Scan Operation

Put-Item Operation

Upvotes: 1

Related Questions