我在AWS Lambda中编写了以下函数
var AWS = require('aws-sdk'); //aws-sdk is node.js sdk for AWS
var nforce = require('nforce'); //nforce is node.js REST API Wrapper for Salesforce
//Make connection to connected App - Start
var org = nforce.createConnection({
clientId: 'Client_ID',
clientSecret: 'CLIENT_SECRENT',
redirectUri: 'http://localhost:3000/oauth/_callback',
apiVersion: 'v45.0', // optional, defaults to current salesforce API version
environment: 'production', // optional, salesforce 'sandbox' or 'production', production default
mode: 'single' // optional, 'single' or 'multi' user mode, multi default
});
//Make Connection to connected App - End
// Authenticate single-user mode - Start
org.authenticate({ username: 'USER_NAME', password: 'PASSWORD'}, function(err, resp){
// the oauth object was stored in the connection object
if(!err) {
console.log('Cached Token: ' + org.oauth.access_token);
}else{
console.log("Error authenticating to Salesforce, " + err);
}
});
//Authenticate single-user mode - End
上面的代码在第2行失败,并出现以下错误
"errorMessage": "Cannot find module 'nforce'",
答案 0 :(得分:0)
您还可以将nforce模块作为一个层上传,然后上面的代码也将起作用。