The deployAws function packages project files into a zip archive and deploys them to the AWS Lambda function eloqua_test in the us-west-2 region.
npm run import -- "deploy aws"function deployAws() {
return execCmd(os.platform() === 'win32' ? `
powershell.exe -nologo -noprofile -command "& { \
Add-Type -A 'System.IO.Compression.FileSystem'; \
Remove-Item –path index.zip –recurse -erroraction 'silentlycontinue'; \
$files = @('index.js', 'eloqua-service.js', 'eloqua-create.js', 'eloqua-mapper.js', 'https-request-polyfill.js', 'sync-zuora-eloqua.js', 'zuora-service.js', 'zuora-renewals-query.js', 'package.json', 'package-lock.json'); \
$files | Compress-Archive -DestinationPath index.zip; \
& aws lambda update-function-code --region us-west-2 --function-name eloqua_test --zip-file fileb://index.zip; \
}"` : `
rm index.zip
zip ./index.zip -r index.js eloqua-service.js eloqua-create.js eloqua-mapper.js https-request-polyfill.js sync-zuora-eloqua.js zuora-service.js zuora-renewals-query.js package.json package-lock.json
aws lambda update-function-code --region us-west-2 --function-name eloqua_test --zip-file fileb://index.zip
`, {cwd: PROJECT_PATH});
}
/**
* Deploys an AWS Lambda function using the provided script.
*
* @returns {Promise} The output of the deployed function.
*/
async function deployAws() {
const { platform } = process;
const command = platform === 'win32'
? `
# PowerShell script to deploy an AWS Lambda function
Add-Type -A 'System.IO.Compression.FileSystem'
Remove-Item –path index.zip –recurse -erroraction'silentlycontinue'
$files = @(
'index.js',
'eloqua-service.js',
'eloqua-create.js',
'eloqua-mapper.js',
'https-request-polyfill.js',
'sync-zuora-eloqua.js',
'zuora-service.js',
'zuora-renewals-query.js',
'package.json',
'package-lock.json'
)
$files | Compress-Archive -DestinationPath index.zip
aws lambda update-function-code --region us-west-2 --function-name eloqua_test --zip-file fileb://index.zip
`
: `
# Bash script to deploy an AWS Lambda function
rm index.zip
zip./index.zip -r index.js eloqua-service.js eloqua-create.js eloqua-mapper.js https-request-polyfill.js sync-zuora-eloqua.js zuora-service.js zuora-renewals-query.js package.json package-lock.json
aws lambda update-function-code --region us-west-2 --function-name eloqua_test --zip-file fileb://index.zip
`;
try {
const { stdout, stderr } = await execCmd(command, { cwd: PROJECT_PATH });
return stdout.trim();
} catch (error) {
console.error(`Error deploying AWS Lambda function: ${stderr.trim()}`);
return Promise.reject(error);
}
} This code defines a function deployAws that deploys a Lambda function named eloqua_test to the AWS us-west-2 region.
Here's a breakdown:
Platform Check:
os.platform().win32), it executes a PowerShell script.File Preparation:
index.zip file.index.zip containing the necessary JavaScript files (index.js, eloqua-service.js, etc.) and project dependencies (package.json, package-lock.json).AWS Lambda Deployment:
aws lambda update-function-code command to update the code for the eloqua_test Lambda function.us-west-2 region and provides the path to the index.zip file.Environment Variables:
PROJECT_PATH environment variable, which likely points to the directory containing the project files.Error Handling:
execCmd function (not shown) is likely responsible for executing the commands and handling any errors.Let me know if you have any more questions!