title: Using list_append with list of maps in DynamoDB
body: <p>I have a DynamoDB table with a schema similar to the below. I want to essentially run an "upsert" function on the <code>jobs</code> attribute that will either add the jobs attribute or append to the list.</p>
  
  <p>When executing my code, I am getting an error message:</p>
  
  <blockquote>
    <p>An error occurred (ValidationException) when calling the UpdateItem operation: Invalid UpdateExpression: Incorrect operand type for operator or function; operator or function: list_append, operand type: M</p>
  </blockquote>
  
  <p>Schema:</p>
  
  <pre><code>{
    "jobs": [
      {
        "event_id": "event_id",
        "job_map": [
          {
            "key1": "val1",
            "key2": "val2"
          }
        ],
        "job_start": "time_stamp"
      }
    ],
    "p_key": "some_id"
  }
  </code></pre>
  
  <p>Example/documentation:</p>
  
  <ol>
  <li><a href="https://forums.aws.amazon.com/thread.jspa?threadID=239939" rel="nofollow noreferrer">Running upsert functions on Dynamo</a></li>
  <li><a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.SET.UpdatingListElements" rel="nofollow noreferrer">Appending to Dynamo lists</a></li>
  <li><a href="https://stackoverflow.com/questions/33278475/dynamodb-set-list-append-not-working-using-aws-sdk">SO question with answers I am pretty sure I'm following</a></li>
  </ol>
  
  <p>Sample code:</p>
  
  <pre><code>p_key_string = 'some_id'
  event_id = '123'
  job_start = 'timestamp_string'
  
  task_map = []
  for item in items:
      task_map.append({
          "M": {
              'key1': {"S": item.get('val1')},
              'key2': {"S": item.get('val2')}
          }
      })
  
  args = {
      'Key': {
          'p_key': p_key_string
      },
      'UpdateExpression': "SET p_key = :p_key, #ri = list_append(#ri, :vals)",
      'ConditionExpression': "attribute_not_exists(p_key) OR p_key = :p_key",
      'ExpressionAttributeNames': {
          "#ri": "jobs"
      },
      'ExpressionAttributeValues': {
          ':p_key': p_key_string,
          ':vals': {
              "L": [{
                  "M": {
                      "event_id": { "S": event_id},
                      "job_start": { "S": job_start},
                      'job_map': { "L": task_map}
                  }
              }]
          }
      }
  }
  
  dynamo_client.update_item(**args)
  </code></pre>
  
  <p>Based on the error I tried a simpler query, but actually got the same error.</p>
  
  <pre><code>...
  ':vals': {
      "L": [
          { "S": event_id},
          { "S": job_start}
      ]
  }
  ...
  </code></pre>
  
  <p>So really not sure what I am missing.</p>