@gp_jcisneros/aws-utils
Version:
AWS SDK utilities for GreenPay microservices
73 lines (63 loc) • 1.91 kB
JavaScript
const { LambdaUtils, invokeLambda } = require('../src/index');
// Example 1: Basic Lambda invocation
async function basicLambdaExample() {
try {
const result = await LambdaUtils.invokeLambda('my-test-function', {
action: 'test',
data: { message: 'Hello from Lambda!' }
});
console.log('Lambda result:', result);
} catch (error) {
console.error('Lambda invocation failed:', error.message);
}
}
// Example 2: Async Lambda invocation
async function asyncLambdaExample() {
try {
const result = await LambdaUtils.invokeLambdaAsync('my-async-function', {
action: 'process',
data: { userId: '123', amount: 100 }
});
console.log('Async Lambda result:', result);
} catch (error) {
console.error('Async Lambda invocation failed:', error.message);
}
}
// Example 3: Using convenience function
async function convenienceExample() {
try {
const result = await invokeLambda('my-function', { test: 'data' });
console.log('Convenience function result:', result);
} catch (error) {
console.error('Convenience function failed:', error.message);
}
}
// Example 4: Get function configuration
async function getConfigExample() {
try {
const config = await LambdaUtils.getFunctionConfiguration('my-function');
console.log('Function configuration:', config);
} catch (error) {
console.error('Failed to get function config:', error.message);
}
}
// Run examples
async function runExamples() {
console.log('=== Lambda Examples ===');
await basicLambdaExample();
await asyncLambdaExample();
await convenienceExample();
await getConfigExample();
}
// Export for testing
module.exports = {
basicLambdaExample,
asyncLambdaExample,
convenienceExample,
getConfigExample,
runExamples
};
// Run if this file is executed directly
if (require.main === module) {
runExamples().catch(console.error);
}