logo
down
shadow

How can I list all my Amazon EC2 instances using Node.js in AWS Lambda?


How can I list all my Amazon EC2 instances using Node.js in AWS Lambda?

By : FlervaFlerv
Date : November 14 2020, 04:51 PM
wish helps you The most likely cause is that you are explicitly terminating your Lambda function before it completes the call to EC2 DescribeInstances API.
The reason is that Lambda assumes your code has finished executing as soon as you call context.done(...). And this is happening before the console.log(... data ...) call.
code :
ec2.describeInstances( function(err, data) {
  console.log("\nIn describe instances:\n");
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log("\n\n" + data + "\n\n"); // successful response
  context.done(null, 'Function Finished!');  
});


Share : facebook icon twitter icon
node.js performance for amazon EC2 instances with ECU's

node.js performance for amazon EC2 instances with ECU's


By : Khaisman
Date : March 29 2020, 07:55 AM
will be helpful for those in need Amazon ECU are virtual core because they are basically virtual sever with 2 real core of a xeon processor.So a box with real 2 core will perform better than a virtual ECU.And also I dont think than amazon ECU are the same thing like the real cpu core Amazon elastic cloud. As far i am working with nodejs and EC2 on my production server i simply set up two thing to utilize the max cpu power of a m1.large instance.
Invoke amazon lambda function from node app

Invoke amazon lambda function from node app


By : taliove
Date : March 29 2020, 07:55 AM
This might help you Since you are using a node.js server you can just invoke your lambda directly with the AWS JavaScript SDK(https://www.npmjs.com/package/aws-sdk). This way you don't have to worry about using API Gateway.
Invoking from your server is as simple as:
code :
var AWS = require('aws-sdk');

// you shouldn't hardcode your keys in production! See http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html
AWS.config.update({accessKeyId: 'akid', secretAccessKey: 'secret'});

var lambda = new AWS.Lambda();
var params = {
  FunctionName: 'myImageProcessingLambdaFn', /* required */
  Payload: PAYLOAD_AS_A_STRING
};
lambda.invoke(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});
Amazon RDS node In AWS Explorer (AWS Toolkit for Eclipse) Does not show DB instances

Amazon RDS node In AWS Explorer (AWS Toolkit for Eclipse) Does not show DB instances


By : Marian
Date : March 29 2020, 07:55 AM
I wish this helpful for you Change the region you are looking at to the same region your RDS instances reside in.
Node js - Moving a file from /tmp in Amazon Lambda to an s3bucket

Node js - Moving a file from /tmp in Amazon Lambda to an s3bucket


By : Abeer Othman
Date : March 29 2020, 07:55 AM
To fix this issue I am trying to write a simple screenshot program in amazon lambda which will take a screengrab of a given url in the following JSON format: , Try this
code :
'use strict';
exports.handler = function(event, context, callback) {

var AWS = require('aws-sdk');
var fs = require('fs');
var webshot = require('webshot');
var request = require('request');
var s3bucket = '<bucket-name>';

console.log( "Attempting to screenshot:", event.site);

  var parts = event.site.split('?'),
      base64Key = new Buffer(parts[0].toLowerCase()).toString('base64').replace(/\//g, '|').replace(/\+/g, '$') + '.png',
      options = {
        shotSize: {
          width: event.width,
          height: event.height
        }
      },
      s3 = new AWS.S3(),
      renderStream = webshot(event.site, options),
      file = fs.createWriteStream('/tmp/' + base64Key, {encoding: 'binary'}),
      bin = '';

  renderStream.on('data', function(data) {
    // bin += data.toString('binary');
    file.write(data.toString('binary'), 'binary');
  });

  renderStream.on('end', function() {

        fs.readFile(path, function (err, file_buffer) {

            var params = {
                Bucket: s3bucket,
                Key: 'base64Key',
                Body: file_buffer
            };

            s3.putObject(params, function (err, pres) {
                if (err) {
                   callback(err);
                } else {
                      callback(null, 'Image uploaded to Amazon s3 bucket: ' + s3bucket);
                }
            });
        });
  });
}
Upload generated PNG to amazon S3 from node on lambda

Upload generated PNG to amazon S3 from node on lambda


By : Daiwh
Date : March 29 2020, 07:55 AM
wish help you to fix your issue See solution below. It was an async issue. Took notes from here. Once the pipe to create the temporary file has finished the s3 stuff kicks off. NB the use of createReadStream which is mentioned here.
code :
const promArr = [promise1, promise2];

Promise.all(promArr).then(() => {
  const diff = new PNG({ width: dimensions1[0], height: dimensions1[1] });
  const pix = pixelmatch(png1.data, png2.data, diff.data, dimensions1[0], dimensions1[1], { threshold: 0.1 });
  const size = dimensions1[0] * dimensions1[1];
  const percentage = ((pix / size) * 100);

  diff.pack().pipe(fs.createWriteStream(`/tmp/${targetHash}.png`).on('finish', () => {
  const fileBuffer = fs.createReadStream(`/tmp/${targetHash}.png`);

    const s3 = new AWS.S3();
    s3.putObject({
      ACL: 'public-read',
      Key: targetFilename,
      Body: fileBuffer,
      Bucket: targetBucket,
      ContentType: 'image/png',
    }, (err) => {
      if (err) {
        console.warn(err);
        cb(err);
      } else {
        cb(null, {
          percentage,
          hash: `${targetFilename}`,
          key: `${targetFilename}`,
          bucket: targetBucket,
          url: `${event.stageVariables.endpoint}${targetFilename}`,
        });
      }
      return;
    });
  }));
})
.catch((err) => {
  console.warn(`error: ${err}`);
  cb(err);
});
Related Posts Related Posts :
  • how we will know on the server side if the peer still connected using Nodejs WebRTC
  • Docker Remote API & Binds
  • Serving multiple node apps with nginx on same domain
  • Waiting for user to enter input in Node.js
  • How to get instant changes in background from private api in mobile app?
  • Grunt.js: Fire livereload as soon a files are modified, before task completes
  • How to remove port number from appear in the url for node js application?
  • How to ignore libraries in browserify programmatic api
  • Node/Express/Jade style guides?
  • how do I return data from a node.js request call? (undefined is not a function)
  • res.sendfile() doesn't serve javascripts well
  • File path completion relative to the current file directory
  • Tuning node-mongodb-native connection pool size
  • Express Socket.io example server not working
  • node js can't install right on my Ubuntu computer
  • How can i do an "or" query in a Model.find on Sails?
  • Confused in starting a project in node.js with npm install
  • unit testing express route with async callback
  • Mongoose sum operation in collection
  • document save function not working in mongoose
  • Why is the zlib inflate function is not working in correct order in node.js?
  • Nested if inside each (Handlebars template in Express app)
  • How does the cookie-session middleware work in expressjs?
  • grunt-processhtml remove not working when specifying a target
  • Error: CERT_HAS_EXPIRED in Node.js request module (macu vs facebook)
  • Async web requests are making 'socket hangup' in node.js
  • ExpressJS: Middleware control flow for Router.param() & Router.use()
  • Glob recursive/zero or more directories, excluding directories
  • node.js v0.11.14 as service with --harmony
  • Running npm install from Sublime Text 2 doesn't work
  • update on a subdoc with mongoose
  • NodeJS Aerospike UDF execute memory leak
  • Alternative to path module that always uses forward-slashes?
  • How do you stream a csv file into a node web app?
  • How to modularize routing with Node.js Express
  • NodeJS - Modularising SQLite3
  • MongoDB / Node: Incorrect Arguments
  • How to use Aggregate in mongoose
  • How to generate multiple reports with mocha?
  • AWS Lambda making video thumbnails
  • MEAN stack on Ubuntu 14.04 suddenly stopped working
  • node.js/express/mongoose noob issue
  • Nodejs ssh convert output byte stream to a sliceable string
  • different behavior of process.argv
  • How to expose the Application model's register method
  • How to install FFMPEG on Node/Meteor server?
  • How Can I Use vhost to Redirect a Sub-Domain to an ExpressJS Route?
  • Gmail API not respecting UTF encoding in subject
  • installing Node modules on Docker: why are they disappearing?
  • How do I set up Node/Express to act as a STUN server?
  • What is the Linear Execution Model in Meteor?
  • connect-redis and express-session results in req.session undefined
  • Application Error Heroku - Problems with Deployment
  • How to pass node v8 args and script args to pm2?
  • Can it be necessary to require a module (child_process in this case) more than once?
  • Too many bad command: outbound emails with Haraka
  • what does require("child_process") actually do?
  • Passing param to custom middleware
  • How do I debug "Error: spawn ENOENT" on node.js?
  • Proper way to combine route and api auth using loopback.js
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org