[英]AWS DynamoDB Transactions with JavaScript: One or more parameter values were invalid
[英]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
的其余屬性是: age
, bio
, email
, name
依次。
登錄並以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.