1

I am working with amazon aws server and writing an application to access my instances. But I am not able to pass around the amazon global config variable to the javascript file that gets executed when the button is clicked.

This is my structure --

app.js -.

var express = require('express')
, http = require('http')
, us = require('underscore')
, aws =  require('aws-sdk')
, fs = require('fs');

....

var contents = fs.readFileSync("aws_config/LAUNCH.config.json");
var launch_config = JSON.parse(contents);

var contents = fs.readFileSync("aws_config/AWS_CREDENTIALS.config.json");
var aws_config = JSON.parse(contents);

aws.config.update({
   accessKeyId: aws_config.accessKeyId,
   secretAccessKey: aws_config.secretAccessKey,
   region: aws_config.region 
});

...

app.get('/', function(req, res){
res.render("index.jade",{aws_config_file : aws_config, 
                       launch_config_file : launch_config,
                       aws_var : aws});
});

...

This the point where I show some HTML in the index page and and have an form with button which gets the status of the instance from the server. So

index.jade

  p.buttons
  input(type = "button", style='value = 'Check' , onclick = "t(aws_config_file,launch_config_file,aws_var)")

Now in my t() function in another file I use the amazon API ..

t(aws_config_file,launch_config_file,aws) {
   **var ec2 = new aws.EC2();**
   **var autoscaling = new aws.AutoScaling();**

   perform the check.. call the aws call back provided in the API.

}

How can I use the aws variable that I defined in the app.js file in the function t(). I tried declaring the aws variable in function t .. even that does not work.

Can someone help.

Thanks

2
  • 1
    Why not have the onclick do an AJAX call to an endpoint that will handle all of the AWS interactions (responding with the desired data from AWS to the client)? That way the function itself can live serverside where there's access to the server's variables. Commented Jul 24, 2013 at 20:39
  • Thanks .. But I have a new problem -- stackoverflow.com/questions/17845212/… Commented Jul 24, 2013 at 21:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.