How to set a DynamoDB Map property value, when the map doesn't exist yet : <p>How do you "upsert" a property to a DynamoDB row. E.g. <code>SET address.state = "MA"</code> for some item, when <code>address</code> does not yet exist?</p>

<p>I feel like I'm having a chicken-and-egg problem because DynamoDB doesn't let you define a sloppy schema in advance.</p>

<p>If <code>address</code> DID already exist on that item, of type <code>M</code> (for Map), the internet tells me I could issue an UpdateExpression like:</p>

<p><code>SET #address.#state = :value</code></p>

<p>with <code>#address</code>, <code>#state</code>, and <code>:value</code> appropriately mapped to <code>address</code>, <code>state</code>, and <code>MA</code>, respectively.</p>

<p>But if the <code>address</code> property does <strong>not</strong> already exist, this gives an error:</p>

<p>'''
ValidationException: The document path provided in the update expression is invalid for update
'''</p>

<p>So.. it appears I either need to:</p>

<ol>
<li>Figure out a way to "upsert" <code>address.state</code> (e.g., <code>SET address = {}; SET address.state = 'MA'</code> in a single command)</li>
</ol>

<p>or</p>

<ol start="2">
<li>Issue three (!!!) roundtrips in which I try it, <code>SET address = {};</code> on failure, and then try it again.</li>
</ol>

<p>If the latter.... how do I set a blank map?!?</p>

<p>Ugh.. I like Dynamo, but unless I'm missing something obvious this is a bit crazy..</p>
