当前位置: 首页 > 知识库问答 >
问题:

KeyConditionExpression无效:运算符或函数的操作数类型不正确;运算符或函数:以开头

姜业
2023-03-14

这是lambda函数的index.js

const getUsersByCompanyId = require('./getUsersByCompanyId')

exports.handler = async(event) => {
    const { arguments, info: { fieldName } } = event
    
    switch (fieldName) {
        case 'getUsersByCompanyId':
            const data =  await getUsersByCompanyId(arguments.companyId)
            console.log(data)
        default:
           return null
    }
    
};

这是我的lambda函数的getUsersByCompanyId。js公司

const AWS = require('aws-sdk')
const docClient = new AWS.DynamoDB.DocumentClient()

async function getUsersByCompanyId(companyId){
    const params = {
        TableName: "CompanyA",
        KeyConditionExpression: `PK = :companyId AND begins_with ( SK, :sk )`,
        ExpressionAttributeValues:{
            ':companyId' : companyId,
            ':sk': {"S": "USER#"}
        }
    }
    try{
        const data = await docClient.query(params).promise() 
        return data
    }catch(err){
        return err
    }
}

module.exports = getUsersByCompanyId

共有1个答案

崔宜修
2023-03-14

我改变了我的getUsersByCompanyId.js:

const AWS = require('aws-sdk')
const docClient = new AWS.DynamoDB.DocumentClient()

async function getUsersByCompanyId(companyId){
    const params = {
        TableName: "CompanyA",
        KeyConditionExpression: `PK = :companyId and begins_with(SK, :sk)`,
        ExpressionAttributeValues:{
            ':companyId' : companyId,
            ':sk': "USER#"
        }
    }
    try{
        const data = await docClient.query(params).promise() 
        return data
    }catch(err){
        return err
    }
}

module.exports = getUsersByCompanyId

我希望有更多关于Direct Lambda解析器的教程,我发现这个教程有点帮助,https://www.twitch.tv/videos/731600097,这是该教程的资源https://gist.github.com/dabit3/96dc51e688b18a7d40fc534331758c56

 类似资料: