You can use @DynamoDBIgnore - AWS documentation

In your example:

    @DynamoDBIgnore
    public String getContent() {
        return content;
    }
Answer from mikethe on Stack Overflow
🌐
AWS
docs.aws.amazon.com › aws sdk for java › developer guide for version 2.x › calling aws services from the aws sdk for java 2.x › work with dynamodb › map java objects to dynamodb items with the aws sdk for java 2.x › use advanced mapping features › explicitly include or exclude attributes
Explicitly include or exclude attributes - AWS SDK for Java 2.x
The DynamoDB Enhanced Client API offers annotations to exclude data class attributes from becoming attributes on a table. With the API, you can also use an attribute name that's different from the data class attribute name. To ignore attributes that should not be mapped to a DynamoDB table, ...
Discussions

DynamoDB ProjectionExpression exclude attribute (all fields except one)
I have a requirement where my dynamodb table has many attributes, and i need all of them in the projection expression except one or two columns which i dont need in response. (I am scanning the tab... More on repost.aws
🌐 repost.aws
1
0
March 28, 2019
java - How ignore some fields in putitem in DynamoDB - Stack Overflow
BTW: I did not use DynamoDBMapper. ... Creates a new item, or replaces an old item with a new item. If an item that has the same primary key as the new item already exists in the specified table, the new item completely replaces the existing item ... Edits an existing item's attributes, or adds ... More on stackoverflow.com
🌐 stackoverflow.com
amazon dynamodb - Dynamically ignore attributes when saving items with .NET AWS SDK Object Persistence Model - Stack Overflow
Is it possible to dynamically ignore some properties when saving items with the .NET Object Persistence Model? I don't want to decorate my class properties with DynamoDBIgnore because sometimes I do More on stackoverflow.com
🌐 stackoverflow.com
DynamoDB Enhanced client should ignore @Transient properties
The DynamoDB Enhanced client, when building a TableSchema.fromClass, lists the properties and then tries to map them onto DynamoDB attributes. However, the code as it currently stands is incompatib... More on github.com
🌐 github.com
6
April 13, 2021
🌐
AWS
sdk.amazonaws.com › java › api › latest › software › amazon › awssdk › enhanced › dynamodb › mapper › annotations › DynamoDbIgnoreNulls.html
DynamoDbIgnoreNulls (AWS SDK for Java - 2.41.25)
Specifies that when calling TableSchema.itemToMap(Object, boolean), a separate DynamoDB object that is stored in the current object should ignore the attributes with null values.
🌐
AWS
sdk.amazonaws.com › java › api › latest › software › amazon › awssdk › enhanced › dynamodb › mapper › annotations › DynamoDbIgnore.html
DynamoDbIgnore (AWS SDK for Java - 2.42.35)
@Target(METHOD) @Retention(RUNTIME) @SdkPublicApi public @interface DynamoDbIgnore · Opts this attribute out of participating in the table schema. It will be completely ignored by the mapper.
🌐
AWS re:Post
repost.aws › questions › QUJjk4gqeKSlCpVo11EPvBFA › dynamodb-projectionexpression-exclude-attribute-all-fields-except-one
DynamoDB ProjectionExpression exclude attribute (all fields except one) | AWS re:Post
March 28, 2019 - There is not an "all but X attributes" type of filter or syntax for projections, you have to list out all the attributes you want to project if you only want a subset. ... How to Delete all Dynamodb records except last 1 year (dynamodb table does not have a TTL attribute set)
🌐
Stack Overflow
stackoverflow.com › questions › 57805916 › dynamically-ignore-attributes-when-saving-items-with-net-aws-sdk-object-persist
amazon dynamodb - Dynamically ignore attributes when saving items with .NET AWS SDK Object Persistence Model - Stack Overflow
The lower level API (exposed through IAmazonDynamoDB / AmazonDynamoDbClient) is the only way I have found till now of updating individual properties of an existing DynamoDB document. ... var updateItemRequest = new UpdateItemRequest { TableName = "search_log_table", Key = new Dictionary<string, AttributeValue> { {"PK", new AttributeValue("pk_value")}, {"SK", new AttributeValue("sk_value")} }, UpdateExpression = $"SET SearchCount = if_not_exists(SearchCount, :start) + :inc", ExpressionAttributeValues = new Dictionary<string, AttributeValue> { {":start", new AttributeValue {N = "0"}}, {":inc", new AttributeValue {N = "1"}} }, ReturnValues = "UPDATED_NEW" }; // _client is an instance of IAmazonDynamoDB return _client.UpdateItemAsync(updateItemRequest);
🌐
GitHub
github.com › aws › aws-sdk-java-v2 › issues › 2347
DynamoDB Enhanced client should ignore @Transient properties · Issue #2347 · aws/aws-sdk-java-v2
April 13, 2021 - The DynamoDB Enhanced client, when building a TableSchema.fromClass, lists the properties and then tries to map them onto DynamoDB attributes. However, the code as it currently stands is incompatible with Groovy, because it looks for a m...
Author   aws
Find elsewhere
🌐
Open Source at AWS
aws.github.io › aws-dynamodb-encryption-java › com › amazonaws › services › dynamodbv2 › datamodeling › encryption › HandleUnknownAttributes.html
HandleUnknownAttributes (aws-dynamodb-encryption-java :: SDK1 2.0.3 API)
Marker annotation that indicates that attributes found during unmarshalling that are in the DynamoDB item but not modeled in the mapper model class should be included in for decryption/signature verification. The default behavior (without this annotation) is to ignore them, which can lead to ...
Top answer
1 of 5
6

This is a much simpler answer.

It works when you consider ExpressionAttributeValues an object.

Here's the code:

params.TableName = ddbTable;
params.UpdateExpression =  "set LastPostedDateTime = :l" ;
if (req.body.AttachmentDescription)  { params.UpdateExpression  += ", AttachmentDescription = :d"; }
if (req.body.AttachmentURL)          { params.UpdateExpression  += ", AttachmentURL = :a"; }

so first we build up the expression if values are available to be passed, using a simple concatenation technique.

Then we supply the values:

params.ExpressionAttributeValues = {};
params.ExpressionAttributeValues[':l'] =  formattedDate ;
if (req.body.AttachmentDescription)  { params.ExpressionAttributeValues[':d']= req.body.AttachmentDescription ; }
if (req.body.AttachmentURL)          { params.ExpressionAttributeValues[':a']= req.body.AttachmentURL ; }

The difficulty is with ExpressionAttributeValues which here, we treat as an object and we can add to the object if we first define it as an object, hence the {}.

Then if the object does not already have the property name it adds it and then adds the value.

The net result is you can have very wide flat records as your records can be extended with variable field names. I.e. this application lists a URL and descriptor. With variable field names, I could add more URLs and descriptors to the same record. There is ultimately a memory limit, yet this type of application, for a few variable fields, would be sufficient for my application.

2 of 5
4

I was asking the same question...In Java there's the SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES but I couldn't find anything like that in aws-sdk for nodejs.

You could use AttributeUpdates instead of UpdateExpression to make a cleaner workaround:

const AWS      = require(aws-sdk);
const bluebird = require('bluebird');
const _        = require('lodash');

AWS.config.setPromisesDependency(bluebird);

const dynamodb = new AWS.DynamoDB.DocumentClient();

var skipNullAttributes = (attributes) => {
  return _.omitBy(attributes, (attr) => { 
    return _.isNil(attr.Value); 
  }); 
}

var update = (id, attributes) => {
  var params = {
    TableName       : 'MyTableName',
    Key             : { id: id },
    AttributeUpdates: skipNullAttributes(attributes)
  };

  return dynamodb.update(params).promise();
}

exports.handler = (event, context, callback) => {
  var body   = JSON.parse(event.body);
  var userId = event.pathParameters.id;

  var attributes = {
    firstName: { Action: 'PUT', Value: body.firstName },
    lastName : { Action: 'PUT', Value: body.lastName  }
  };

  update(userId, attributes)
    .then((result) => console.log(result) )
    .catch((error) => console.error(error) );

  callback(null, {statusCode: 200, body: JSON.stringify({message: 'done!'})});
}
🌐
GitHub
github.com › aws › aws-sdk-java › issues › 2695
DynamoDB Mapper attributeName not honored on member variable with identical name · Issue #2695 · aws/aws-sdk-java
January 7, 2022 - Describe the bug When the DynamoDBAttribute annotation is applied to a member variable rather than the corresponding getter, the attributeName parameter is ignored if it is identical to the member variable name. While this may not initia...
Author   aws
🌐
GitHub
github.com › aws › aws-sdk-net › issues › 1117
DynamoDB should ignore static fields/properties · Issue #1117 · aws/aws-sdk-net
November 6, 2018 - Expected Behavior Static fields and properties on model types should be ignored. Current Behavior An attempt is made to serialize static fields and properties. Steps to Reproduce (for bugs) The following is a common pattern in small type...
Author   aws