This Lambda function automates the export of data from Zuora to Eloqua, handling data mapping and upload to Eloqua's system.
npm run import -- "aws entry point"
var importer = require('../Core');
var eloquaUpload = importer.import("bulk upload eloqua");
var zuoraExport = importer.import("zuora export month");
var mapper = importer.import("zuora eloqua mapper");
function handler(event, context, callback) {
const zuoraConfig = {
"rest_api_user": process.env.ZUORA_API_USER,
"rest_api_password": process.env.ZUORA_API_PASS,
"rest_api_url": process.env.ZUORA_API_URL
};
const eloquaConfig = {
"authorize_uri": process.env.ELOQUA_AUTHORIZE_URL,
"token_uri": process.env.ELOQUA_TOKEN_URL,
"rest_api_url": process.env.ELOQUA_API_URL,
"rest_client_id": process.env.ELOQUA_CLIENT_ID,
"rest_secret": process.env.ELOQUA_CLIENT_SECRET,
"rest_api_company": process.env.ELOQUA_API_COMPANY,
"rest_api_user": process.env.ELOQUA_API_USER,
"rest_api_password": process.env.ELOQUA_API_PASS
};
return zuoraExport.getZuoraMonth(0, zuoraConfig)
.then(records => mapper.mapDataToFields(records))
.then(accounts => eloquaUpload.bulkUploadEloqua(accounts, eloquaConfig))
.then(() => callback(null, {
'statusCode': 200,
'headers': { 'Content-Type': 'text/plain' },
'body': 'Success!'
}))
.catch(e => callback(e.message || e.body || e, {
'statusCode': 500,
'headers': { 'Content-Type': 'text/plain' },
'body': 'Error: ' + e.message
}))
}
module.exports = {
handler
};
// Import required modules
const Core = require('../Core');
const { bulkUploadEloqua, getZuoraMonth } = Core.import('bulk upload eloqua');
const { mapDataToFields } = Core.import('zuora eloqua mapper');
const { zuoraExport } = Core.import('zuora export month');
// Define a configuration object with environment variable values
const getEnvironmentVariable = (name) => process.env[name.replace('_', '/')];
const config = {
zuora: {
restApiUser: getEnvironmentVariable('ZUORA_API_USER'),
restApiPassword: getEnvironmentVariable('ZUORA_API_PASS'),
restApiUrl: getEnvironmentVariable('ZUORA_API_URL'),
},
eloqua: {
authorizeUri: getEnvironmentVariable('ELOQUA_AUTHORIZE_URL'),
tokenUri: getEnvironmentVariable('ELOQUA_TOKEN_URL'),
restApiUrl: getEnvironmentVariable('ELOQUA_API_URL'),
restClientId: getEnvironmentVariable('ELOQUA_CLIENT_ID'),
restSecret: getEnvironmentVariable('ELOQUA_CLIENT_SECRET'),
restApiCompany: getEnvironmentVariable('ELOQUA_API_COMPANY'),
restApiUser: getEnvironmentVariable('ELOQUA_API_USER'),
restApiPassword: getEnvironmentVariable('ELOQUA_API_PASS'),
},
};
// Define the handler function
function handler(event, context, callback) {
// Get the Zuora month data
zuoraExport.getZuoraMonth(0, config.zuora)
.then((records) => {
// Map Zuora data to Eloquent fields
return mapDataToFields(records);
})
.then((accounts) => {
// Bulk upload Eloquent data
return bulkUploadEloqua(accounts, config.eloqua);
})
.then(() => {
// Return success response
callback(null, {
'statusCode': 200,
'headers': { 'Content-Type': 'text/plain' },
'body': 'Success!',
});
})
.catch((error) => {
// Return error response
callback(error.message || error.body || error, {
'statusCode': 500,
'headers': { 'Content-Type': 'text/plain' },
'body': 'Error:'+ error.message,
});
});
}
// Export the handler function
module.exports = { handler };
This code defines a Lambda function handler that exports data from Zuora to Eloqua.
Here's a breakdown:
Imports:
importer
: A module likely providing utilities for importing other modules.bulk upload eloqua
: A module for uploading data to Eloqua.zuora export month
: A module for exporting data from Zuora.zuora eloqua mapper
: A module for mapping data between Zuora and Eloqua formats.Configuration:
Handler Function:
handler(event, context, callback)
: The Lambda function handler.zuoraExport.getZuoraMonth(0, zuoraConfig)
to export data from Zuora for the current month.mapper.mapDataToFields(records)
.eloquaUpload.bulkUploadEloqua(accounts, eloquaConfig)
.Exports:
handler
function, making it available for invocation by AWS Lambda.In essence, this code automates the process of exporting data from Zuora, mapping it to Eloqua's format, and uploading it to Eloqua, likely as part of a data synchronization workflow.