Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
// eslint-disable-next-line import/no-extraneous-dependencies
const instana = require('@instana/aws-lambda'); // provided by Lambda layer "instana"
const fetch = require('node-fetch');
exports.handler = instana.wrap(async event => {
console.log('in actual handler');
await fetch('https://example.com');
if (event.error) {
throw new Error('Boom!');
} else {
return {
message: 'Stan says hi!'
};
}
});
'use strict';
// eslint-disable-next-line import/no-extraneous-dependencies
const instana = require('@instana/aws-lambda'); // provided by Lambda layer "instana"
const https = require('https');
exports.handler = instana.wrap((event, context, callback) => {
console.log('in actual handler');
const req = https.get('https://example.com', res => {
res.resume();
res.on('end', () => {
if (event.error) {
callback(new Error('Boom!'));
} else {
callback(null, {
message: 'Stan says hi!'
});
}
});
});
req.on('error', e => {
callback(e);
});
const fs = require('fs');
const path = require('path');
const DEFAULT_HANDLER = 'index.handler';
const RUNTIME_PATH = '/var/runtime';
const SPLIT_AT_DOT_REGEX = /^([^.]*)\.(.*)$/;
const TWO_DOTS = '..';
const lambdaRuntimeErrors = require(`${RUNTIME_PATH}/Errors.js`);
let wrappedHandler;
if (!wrappedHandler) {
const targetHandler = loadTargetHandlerFunction();
wrappedHandler = instana.wrap(targetHandler);
}
exports.handler = function instanaAutowrapHandler(event, context, callback) {
return wrappedHandler(event, context, callback);
};
function loadTargetHandlerFunction() {
let targetHandlerEnvVar = process.env.LAMBDA_HANDLER;
if (!targetHandlerEnvVar || targetHandlerEnvVar.length === 0) {
targetHandlerEnvVar = DEFAULT_HANDLER;
}
const {
targetHandlerModuleFolder, //
targetHandlerModuleName,
targetHandlerFunctionName