Example usage for com.amazonaws.services.dynamodbv2 AmazonDynamoDB putItem

List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDB putItem

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2 AmazonDynamoDB putItem.

Prototype

PutItemResult putItem(String tableName, java.util.Map<String, AttributeValue> item);

Source Link

Document

Simplified method form for invoking the PutItem operation.

Usage

From source file:amazonsensors.LambdaAmazonSensor.java

@Override
public String handleRequest(AmazonSensor sensor, Context cntxt) {

    AmazonDynamoDB amazonDDB = AmazonDynamoDBClientBuilder.standard().withRegion(Regions.US_WEST_2).build();

    Map<String, AttributeValue> item = new HashMap();
    item.put(SENSOR_FIELD, new AttributeValue(sensor.getSensorID()));
    item.put(TEMPERATURE_FIELD, new AttributeValue(sensor.getTemperature()));

    amazonDDB.putItem(TABLE_NAME, item);

    return sensor.toString();
}

From source file:com.dustindoloff.api_lizanddustin_com.rsvp.SaveRsvpHandler.java

License:Apache License

public void handle(final Map<String, String> saveRsvpRequest, final Context context) {
    final String tableName = getDynamoDBTableName();

    saveRsvpRequest.put("created", getCurrentTimeIso());
    final Map<String, AttributeValue> dataMap = saveRsvpRequest.entrySet().stream()
            .filter(entry -> ALLOWED_KEYS.contains(entry.getKey()))
            .collect(Collectors.toMap(entry -> entry.getKey(), entry -> new AttributeValue(entry.getValue())));

    final AmazonDynamoDB dynamoDbClient = getAmazonDynamoDB();

    dynamoDbClient.putItem(tableName, dataMap);
}

From source file:mx.iteso.msc.asn.temperaturecollector.TemperatureCollector.java

License:Apache License

@Override
public JSONObject handleRequest(Temperature t, Context c) {
    JSONObject json = new JSONObject();
    AmazonDynamoDB db = AmazonDynamoDBClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
    String tableName = "BitacoraLectura";

    c.getLogger()//w ww  .j av  a2s. co m
            .log(("Temperature " + t.getTemperature() + " received from sensor " + t.getSensorId() + "\n"));

    Map<String, AttributeValue> item = new HashMap<>();
    item.put("SensorId", new AttributeValue(t.getSensorId()));
    item.put("Temperature", new AttributeValue(Float.toString(t.getTemperature())));
    db.putItem(tableName, item);

    json.put("result", "Ok");

    c.getLogger().log(("Record added\n"));
    return json;
}

From source file:org.apache.metamodel.dynamodb.DynamoDbRowInsertionBuilder.java

License:Apache License

@Override
public void execute() throws MetaModelException {
    final Map<String, AttributeValue> itemValues = new HashMap<>();
    final Column[] columns = getColumns();
    final Object[] values = getValues();
    for (int i = 0; i < columns.length; i++) {
        final Column column = columns[i];
        final Object value = values[i];
        if (column.isPrimaryKey() && value == null) {
            throw new IllegalArgumentException("Value for '" + column.getName() + "' cannot be null");
        }/*from w w w  .j  a  va 2s.  c o m*/

        final AttributeValue attributeValue = DynamoDbUtils.toAttributeValue(value);
        itemValues.put(column.getName(), attributeValue);
    }

    final AmazonDynamoDB dynamoDb = getUpdateCallback().getDataContext().getDynamoDb();
    dynamoDb.putItem(getTable().getName(), itemValues);
}