Trouble connecting to AWS Athena via JDBC using Node Lambda - node.js

My Goal
I am trying to use AWS's JDBC Driver to allow a Lambda function running Node 6.10 to connect to AWS Athena and create a database. (I will also want to be able to create and query against tables inside of that databse).
What I've Tried
I have tried the following code from an answer to a similar question:
var JDBC = require('jdbc');
var jinst = require('jdbc/lib/jinst');
if (!jinst.isJvmCreated()) {
jinst.addOption("-Xrs");
jinst.setupClasspath(['./AthenaJDBC41-*.jar']);
}
var config = {
// Required
url: 'jdbc:awsathena://athena.us-east-1.amazonaws.com:443',
// Optional
drivername: 'com.amazonaws.athena.jdbc.AthenaDriver',
minpoolsize: 10,
maxpoolsize: 100,
properties: {
s3_staging_dir: 's3://aws-athena-query-results-*/',
log_path: '/logs/athenajdbc.log',
user: 'access_key',
password: 'secret_key'
}
};
var hsqldb = new JDBC(config);
hsqldb.initialize(function(err) {
if (err) {
console.log(err);
}
});
The Errors I'm Seeing
When I run this on my own machine (Mac OSX El Capitan 10.11.6), I see the popup pictured below with the message No Java runtime present, requesting install. printed to my console.
When I deploy my code to Lambda and run it there, it fails with the following message:
Error: /var/task/node_modules/java/build/Release/nodejavabridge_bindings.node: invalid ELF header
When run locally, I can see that things fail at the var hsqldb = new JDBC(config); line, but when running on Lambda, the error occurs immediately upon requiring JDBC (the first line of the code above).
Update
The invalid ELF header issue seems to be pointing to the idea that the node_modules/java/build/Release/nodejavabridge_bindings.node file was compiled for an architecture incompatible with the one on which AWS Lambda runs (Linux x64).
This explains the difference in behavior when running locally vs when running on Lambda.
I have tried using node-gyp to compile the resource specifically for the x64 architecture, and saw the issue change but not resolve.
The node-gyp command I ran successfully was node-gyp configure --arch=x64 (run inside the node_modules/java/ directory)
Instead of an invalid ELF header error when running on Lambda, we now see a module initialization error (See logs below)
module initialization error: Error
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/node_modules/java/lib/nodeJavaBridge.js:21:16)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)

You are describing a couple of issues here.
First the missing JVM in MacOS. This is a documented bug within node-java. This link describes a workaround for that issue.
https://github.com/joeferner/node-java/issues/90#issuecomment-45613235
After applying that and changing the "setupClasspath"-statment, your sample should be runnable locally.
jinst.setupClasspath(['./AthenaJDBC41-1.0.1.jar']);
As for the ELF-problem, you cannot build Linux native modules for node in MacOS. And since npm does not distribute prebuild versions, you can only build you deployable on a target equivalent machine.
This means you need to install/package your modules on a Linux AMI (preferably the Lambda AMI).
Here an AWS blog post on how to do this:
https://aws.amazon.com/blogs/compute/nodejs-packages-in-lambda/
AMI versions used:
http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html

Related

Deploy Utility app as Windows Service NodeJS

Working on deploying an app with PKG for Windows as a service via Node-Windows.
I have my NodeWindows install and uninstall scripts, and I'm trying to use PKG to make those into Windows executables. PKG creates the .exe files, but when I run the file, it throws an error like the one below:
pkg/prelude/bootstrap.js:1226
return wrapper.apply(this.exports, args);
^
ReferenceError: svc is not defined
at Object.<anonymous> (C:\snapshot\transient\installTransient2.js:0)
at Module._compile (pkg/prelude/bootstrap.js:1226:22)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (pkg/prelude/bootstrap.js:1281:12)
at run (bootstrap_node.js:432:7)
at startup (bootstrap_node.js:192:9)
at bootstrap_node.js:547:3
with my Node-windows script like this:
var Service = require('node-windows').Service;
var scv = new Service({
name: 'Transient2',
description: 'Yet Another File Transfer Utility in NodeJS',
script: 'server.js'
});
svc.on('install', () => {
console.log('successfully installed');
svc.start();
});
svc.install();
I want to think that node-windows isn't getting packed into the Executable. According to PKG's documentation, it should "shim" in anything in a require statement, unless it's declared with a path.join() call.
How can I package my app in an installer that creates a service in windows?
The hint is in the error - you have declared the variable name 'scv' instead of 'svc' on line 3 in your Node.js script.
This means that when you add the 'install' event handler on line 9 to 'svc' it cannot find that variable because it was misspelt. This is why you're receiving the ReferenceError described.

Lambda function failing with Unable to import module 'index'

Error:
Unable to import module 'index': Error
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/node_modules/slack-incoming-webhook/lib/index.js:3:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
By the looks of this my code isn't the problem it's a problem with the slack-incoming-webhook node-module however the piece of offending code is this line which looks completely normal.
var SlackClient = require('./client');
I have tried 4 different packages now (request, http, node-webhooks and now slack-incoming-webhooks) and they are all failing with code in node modules. I am thoroughly confused as I can get the code to work on my own computer and on an Amazon Linux AMI EC2 Instance (running same node version)
All the code is zipped and sent to lambda using the aws-cli and I have deployed node.js code on lambda before without any problems (alexa skill).
I have tried npm install on the ec2 instance, I have tried several different packages and I have come to the conclusion there must be some sort of configuration wrong in lambda but I can't find what. Could someone point me in the right direction...
Here is my code if anyone is curious also the lambda trigger is an aws iot button.
const slack = require('slack-incoming-webhook');
const send = slack({
url: 'https://hooks.slack.com/....'
});
exports.handler = function ()
{
send(process.env.company + ' has pushed their panic button! PANIC! PANIC! PANIC!');
};
This is common issue I have seen in many posts. Most of the cases it is the way zipping the files making the problem. Instead of zipping the folder you have to select all files and zip it like below,
I would simply refer to use Apex (http://apex.run/).
Pretty much awsm serverless framework to be used with AWS Lambda. Once this is setup, no need to do manual zipping.
Simply execute couple of commands:
apex create (to create the lambda)
apex deploy (deploy to your AWS region, no manual zipping required)
apex invoke to invoke it from your terminal.
Thanks

proxies not supported on this platform

i'm trying to make(i don't know what it's called, hot load? hot reload?) Meteor-like real-time loading of data, but by using node.js not Meteor.
and i'm using the ddp module for the client(=browser, i have not tried it yet) and ddp-reactive-server, well, for the server.
server.js is like this:
var DDPServer = require('ddp-server-reactive');
var server = new DDPServer();
var todoList = server.publish('todolist');
after that i run the server using the command node server.js --harmony_proxies(notice i'm already using the flag) this is what i get:
[aseds#localhost ~]$ node server.js --harmony_proxies
/home/aseds/Desktop/projeh/css-goodness/node_modules/harmony-reflect/reflect.js:2049
throw new Error("proxies not supported on this platform. On v8/node/iojs, make sure to pass the --harmony_proxies flag");
^
Error: proxies not supported on this platform. On v8/node/iojs, make sure to pass the --harmony_proxies flag
at global.Proxy (/home/aseds/Desktop/projeh/css-goodness/node_modules/harmony-reflect/reflect.js:2049:13)
at publish (/home/aseds/Desktop/projeh/css-goodness/node_modules/ddp-server-reactive/lib.js:211:32)
at Object.<anonymous> (/home/aseds/Desktop/projeh/css-goodness/ddpserver.js:10:23)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:429:10)
at startup (node.js:139:18)
at node.js:999:3
my nodejs version v5.4.1.
i'm not even sure if that's actually possible to make the automatic reload feature of Meteor this way but i'm trying! :)
Thanks in advance for any help you are able to provide.
I came across this thread with regards to --harmony-proxies:
https://github.com/tvcutsem/harmony-reflect/issues/56
The relevant bit:
I released version 1.4.0 which, when loaded twice according to the script outlined above, loads correctly.
Note that loading v1.3.1 of this library followed by v1.4.0 will still fail (the other way around works fine). So it's important that your dependencies upgrade to the latest version.
It appears that if harmony-proxies is loaded as a node dependency twice, with different versions required, and a version before 1.4.0 is loaded first, then you will see this error.

Can't get Intern to run their own tutorial

I'm new to NodeJS and even more for Intern trying to learn intern for testing at work but can't start intern-client by their own tutorial step-by-step, it is giving me back always the error:
C:\testproject\root>node ./node_modules/.bin/intern-client config=tests/intern
C:\testproject\root\node_modules\.bin\intern-client:2
basedir=`dirname "$0"`
^
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
I was following the Quick Start from their site https://github.com/theintern/intern and after creating the folders, installing intern through NodeJS and adding their example into the tests/folder. Running their script was not helpful to determinate what is wrong with their tutorial. Set the packages and non functional suites based on their example but still have no success.
//...
loader: {
// Packages that should be registered with the loader in each testing environment
packages: [ { name: 'root', location: '.' } ],
// map: { 'intern-selftest': { dojo: 'intern-selftest/node_modules/dojo' } }
},
// Non-functional test suite(s) to run in each browser
suites: [ 'root/tests/intern' ],
//...
I nuked the entire project several time, used jslint and jshint and got no syntax errors back.
Also tried some unsuccessful combinations with :
https: //github.com/theintern/intern-tutorial
https: //gist.github.com/neonstalwart/6630466
Any ideas or a REALLY working example available?
Thanks in advance.
Why are you putting node at the start of the command? None of the documentation says to do that. You’re trying to run a shell script with Node.js (which, to be clear, Intern did not create that shell script, your installer did), which will never work because JavaScript and sh are not the same language.

Error deploying node js app onto Cloudbees ClickStart

I'm trying to deploy a node app onto the Cloudbees ClickStart.
I've create a node js ClickStart (this creates the jenkins job, git repository and application container).
Zipped up my app, then deployed using the Cloudbees SDK.
bees app:deploy -t nodejs -a nodeshort -v nodeshort.zip
When I try to access the URL the application is deployed on I get a 502 Bad Gateway.
Checking the application logs, I see the following printed multiple times:
module.js:340
throw err;
^
Error: Cannot find module '/mnt/e1/genapp-apps/660f9784/main.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
What has caused this? More importantly, what can I do to resolve it? I've tried trashing the clickstart and recreating, but I get the same outcome each time.
Thanks
The way in which you zip the file is important.
zip -r ../myapp.zip * => WORKS FINE
zip -r myapp.zip myapp/* => DOES NOT WORK
nodejs stack expect a "main.js" script to be present in application rootdir.
You have this nodejs ClickStart working. Maybe you should compare your code with the ClickStart.

Resources