Home > Blockchain >  Float for input parameter for lambda function in amazon
Float for input parameter for lambda function in amazon

Time:04-05

I looked at documentation but couldn't find an answer for that. I am trying to add "rating" of type "float" inside custom lambda function. All I see for items are written as {S: date.toISOString()}. Here "S" stands for I think string, but what if I want it to be a float?

var aws = require('aws-sdk');
var ddb = new aws.DynamoDB();

exports.handler = async (event, context) => {
    
    let date = new Date();

    if (event.request.userAttributes.sub) {

        let params = {
            Item: {
                'id': {S: event.request.userAttributes.sub},
                '__typename': {S: 'User'},
                'name': {S: event.request.userAttributes.name},
                'email': {S: event.request.userAttributes.email},
                'createdAt': {S: date.toISOString()},
                'updatedAt': {S: date.toISOString()},
                'rating': {F: 0}    // is this format true? Or what to do if not?
            },
            TableName: process.env.API_{YOUR_APP_NAME}_USERTABLE_NAME
        };

There are so little documentation for this custom lambda function. Or maybe I couldn't find where the details are explained.

CodePudding user response:

The type for numbers is "N". This is documented https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.DataTypes.html.

DynamoDB has just one number type - an unusual decimal floating point type that can be used to represent either floats or integers. So you don't need to tell it if the number is an integer or a float - you just tell it it's a number.

  • Related