You can use @DynamoDBIgnore - AWS documentation
In your example:
@DynamoDBIgnore
public String getContent() {
return content;
}
Answer from mikethe on Stack OverflowYou can use @DynamoDBIgnore - AWS documentation
In your example:
@DynamoDBIgnore
public String getContent() {
return content;
}
it's @DynamoDbIgnore annotation.. not @DynamoDBIgnore
DynamoDB ProjectionExpression exclude attribute (all fields except one)
java - How ignore some fields in putitem in DynamoDB - Stack Overflow
amazon dynamodb - Dynamically ignore attributes when saving items with .NET AWS SDK Object Persistence Model - Stack Overflow
amazon web services - DynamoDB ProjectionExpression exclude attribute (all fields except one) - Stack Overflow
You will have this problem for a small window or if you run a long living split tests.
We solved with following ways:
- Whichever lambda is using the attributes make sure they check whether property exists and work on it. If a required property does not exist, throw an error and assume it failed. This can be a problem if you are using it in a transactional path, but will let you know what failed and how to fix it. This is for split tests.
- Architect your code for backward compatibility for atleast one version behind. Be sure to remove the code once the desired version is in place.
- If the window is small and not heavily loaded, you can let the service to fail to catch the newer version.
Hope it helps.
Just an update on the issue. After taking @zapl advice on trying to print the stacktrace, I found that there was absolutely nothing wrong with the way the AWS DynamoDB Mapper or SDK works. I was expecting to capture some stacktrace from the SDK, and did not, after some more careful tracing I discovered that the Java Devs misdiagnosed the issue, and the real issue is they had logic to filter a stream which depended on the new fields. So lesson of the story, architect the code for backward compatibility at least one version behind!
In the latest version of the .NET SDK you don't have to put in the attribute tags, it will see all read/write properties and upload the attributes as the same name. You would only have to use the [DynamoDBProperty(...)] if you want the attribute name in DynamoDB to be something other than the .NET object name.
So in your case you could simply remove that attribute for all properties except photo (which needs the converter, you could remove the AttributeName part of it) and WeightKg (because the capitalization is different) and you would get the same result.
I see this is a little bit older question now, so it may not have been that way in older versions (not sure) but I'm using 3.3.0.0 of the SDK and it does work that way. You have probably moved on but answering for others that may come upon this thread as I did...
There is no way, the default "strongly typed" client relies on attributes.
If you have time to do the plumbing yourself - there is nothing stopping your from doing your own implementation of the POC to Dynamo mapping though. Amazon client api (AWSSDK.DynamoDBv2) exposes the raw class AmazonDynamoDBClient which handles all the API calls and the DynamoDBConext is just implementation of IDynamoDBContext interface - which exposes all the "strongly typed" operations. So you can make your own implementation and take different mapping approach in it.
Also you can make a feature request for this: https://github.com/aws/aws-sdk-net/issues
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.
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!'})});
}