繁体   English   中英

DynamoDB数据库查询中的无效参数-Javascript-AWS

[英]Invalid params in DynamoDB database query - Javascript - AWS

我正在使用AWS通过Cognito用户/ IAM角色和策略对dynamoDB进行数据库查询。

听起来我查询DynamoDB的参数无效。

我的错误:dynamodb.html:150 ValidationException:一个或多个参数值无效:条件参数类型与架构类型不匹配

我尝试添加: ProjectionExpression: "name"因为它是我的属性之一,但是name显然是保留字,因此我不能使用它。 我也尝试了age因为它是我拥有的另一个属性,但是我得到了与上述相同的初始错误。 所以我已经删除了ProjectionExpression: :。 这是我现在需要的参数:

var params = {
        ExpressionAttributeValues: {
            ":v1": {
                N: 123456788
            }
        },
        KeyConditionExpression: "userId = :v1",
        TableName: "user"
        };

我不太确定该如何构架。 请让我知道我缺少什么或者是否有任何好的文档,因为我是AWS的新手。 先感谢您!

编辑:

主键是userId ,表user的其余属性是: agebioemailname依次。

登录并以IAM角色查询

var data2 = {
UserPoolId: 'xxxxxxxx',
ClientId: 'xxxxxxxx',
};

var userPool = new AmazonCognitoIdentity.CognitoUserPool(data2);
var cognitoUser = userPool.getCurrentUser();

var userData = {
    Username : 'xxxxxxxx',
    Pool : userPool
    };        

var authenticationData = {
    Username : 'xxxxxxxx',
    Password : 'xxxxxxxx',
};
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);       
var cognitoUser2 = new AmazonCognitoIdentity.CognitoUser(userData);
   cognitoUser2.authenticateUser(authenticationDetails, {
       onSuccess: function (result) {
           var accessToken = result.getAccessToken().getJwtToken(); //user sign-in success and you can get accessToken and IdToken

       //POTENTIAL: Region needs to be set if not already set previously elsewhere.
           AWS.config.region = 'xxxxxxxx';

       AWS.config.credentials = new AWS.CognitoIdentityCredentials({
           IdentityPoolId : 'xxxxxxxx', // your identity pool id here
           Logins : {
               // Change the key below according to the specific region your user pool is in.
               // Here you need to map your idToken with your user pool domain for Cognito Identity Pool to generate a Identity with credential.
               'cognito-idp.xxxxxxxx.amazonaws.com/xxxxxxxx' : result.getIdToken().getJwtToken()     
           }
       });

       //refreshes credentials using AWS.CognitoIdentity.getCredentialsForIdentity()
       AWS.config.credentials.refresh((error) => {
           if (error) {
                console.error(error);
           } else {
               console.log('Successfully logged!');
        // Instantiate aws sdk service objects now that the credentials have been updated. So put your DynamoDB client here
        var docClient = new AWS.DynamoDB.DocumentClient({ region: AWS.config.region });
        var params = {

           ExpressionAttributeValues: {
                ":v1": {
                    N: 123456788
                }
            },
            KeyConditionExpression: "userId = :v1",
            TableName: "user"
            };
          docClient.query(params, function(err, data2) {
            if (err) {
                console.error(err);
            }else{
              console.log(data2);
            }
          }); 
               }
           });
       },
    onFailure: function(err) {
           alert(err.message || JSON.stringify(err));
       },
   });

尝试在ExpressionAttributeValues使用不带N ,并使用"作为用户ID值。

var params = {
        ExpressionAttributeValues: {
            ":v1": "123456788"
        },
        KeyConditionExpression: "userId = :v1",
        TableName: "user"
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM