How to use the aws-sdk.EC2 function in aws-sdk

To help you get started, we’ve selected a few aws-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-health-tools / automated-actions / AWS_ELASTICLOADBALANCING_ENI_LIMIT_REACHED / LambdaFunction.js View on Github external
exports.handler = (event, context, callback) => {
    //extract details from Cloudwatch event
    var eventName = event.detail.eventTypeCode;
    var region = event.region;
    const awsHealthSuccessMessage = `Successfully got details from AWS Health event ${eventName} and executed automated action in ${region}. Further details in CloudWatch Logs.`;

    // we only need to run this automation once per invocation since the issue 
    // of ENI exhaustion is regional and not dependent on the load balancers in the alert
    // Event will only trigger for one region so we don't have to loop that
    AWS.config.update({region: region});
    AWS.config.update({maxRetries: 3});
	ec2 = new AWS.EC2(); // creating the object now that we know event region
	
    console.log ('Getting the list of available ENI in region %s', region);
    var params = {
        Filters: [{Name: 'status',Values: ['available']}]
    };
    
    ec2.describeNetworkInterfaces(params, function(err, data) {
        if (err) 
        {
            console.log( region, err, err.stack); // an error occurred
            callback('Error describing ENIs; check CloudWatch Logs for details');
        }
        else 
        {
            var numberToProcess = data.NetworkInterfaces.length;
            if ((maxEniToProcess > 0) && (data.NetworkInterfaces.length > maxEniToProcess)) numberToProcess = maxEniToProcess;
github wongcyrus / AWSCloudLab / AWSCloudLabCore / lib / Ec2Manager.js View on Github external
return new Promise((resolve, reject) => {
            let ec2 = new AWS.EC2();
            ec2.modifyImageAttribute(params, (err, data) => {
                if (err && err.code === "AuthFailure") {
                    console.log("AuthFailure cannot share! And, it should be public image.");
                    resolve(data);
                }
                if (err) reject(err); // an error occurred
                else resolve(data);           // successful response
            });
        })
    }
github pavjacko / renative / packages / rnv-deploy-aws / index.js View on Github external
const bootstrapS3 = async (configRegion) => {
    const rnvPath = await getInstalledPath('rnv', { local: false });
    const { inquirerPrompt } = require(path.join(rnvPath, 'dist/systemTools/prompt'));
    let s3;
    let region = configRegion;

    // check if we have credentials for AWS
    try {
        await new Promise((resolve, reject) => aws.config.getCredentials((err) => {
            if (err) return reject(err);
            return resolve();
        }));
    } catch (e) {
        // get all the regions from ec2
        const ec2 = new aws.EC2();
        const regions = await ec2.describeRegions().promise();
        const { accessKeyId } = await inquirerPrompt({
            type: 'input',
            name: 'accessKeyId',
            message: 'Your AWS ACCESS_KEY_ID'
        });
        const { secretAccessKey } = await inquirerPrompt({
            type: 'input',
            name: 'secretAccessKey',
            message: 'Your AWS SECRET_ACCESS_KEY'
        });
        if (!region) {
            const regionAnswer = await inquirerPrompt({
                type: 'select',
                name: 'region',
                choices: regions.data.Regions.map(r => r.RegionName),
github pavjacko / renative / packages / rnv-deploy-aws / src / deployer.js View on Github external
async initialize(configRegion) {
        const rnvPath = await getInstalledPath('rnv', { local: false });
        const { inquirerPrompt } = require(path.join(rnvPath, 'dist/systemTools/prompt'));
        const { logDebug } = require(path.join(rnvPath, 'dist/systemTools/logger'));
        this.logDebug = logDebug;
        let region = configRegion;

        // check if we have credentials for AWS
        try {
            await new Promise((resolve, reject) => aws.config.getCredentials((err) => {
                if (err) return reject(err);
                return resolve();
            }));
        } catch (e) {
        // get all the regions from ec2
            const ec2 = new aws.EC2();
            const regions = await ec2.describeRegions().promise();
            const { accessKeyId } = await inquirerPrompt({
                type: 'input',
                name: 'accessKeyId',
                message: 'Your AWS ACCESS_KEY_ID'
            });
            const { secretAccessKey } = await inquirerPrompt({
                type: 'input',
                name: 'secretAccessKey',
                message: 'Your AWS SECRET_ACCESS_KEY'
            });
            if (!region) {
                const regionAnswer = await inquirerPrompt({
                    type: 'select',
                    name: 'region',
                    choices: regions.data.Regions.map(r => r.RegionName),
github aws-quickstart / quickstart-datalake-pariveda / functions / source / ingest-lambda / index.js View on Github external
"m3.medium",
"i2.4xlarge",
"r3.xlarge",
"c4.large",
"p2.8xlarge",
"m4.2xlarge",
"i2.2xlarge",
"x1.16xlarge",
"i3.large",
"r3.8xlarge",
"i3.4xlarge",
"m4.4xlarge",
"i3.8xlarge",
"m3.xlarge"];
	var instanceTypeBatches = split(instanceTypes, 4);
	var ec2 = new AWS.EC2({region: awsRegion});
	var awsRegion = process.env.AWS_REGION;
	var outputStream = process.env.OutputStream;
	console.log('Querying for price history between %s and %s in %d batches', startTime.toISOString(), endTime.toISOString(), instanceTypeBatches.length);
	async.each(instanceTypeBatches, getSpotPrices ,function(err) {
        if(err) {
			callback(err);
        }
        else {
            callback(null);
        }
    });
    
    function getSpotPrices(instanceTypeBatch, callback, nextToken) {
	    var params = {
			EndTime: endTime, 
			InstanceTypes: instanceTypeBatch,
github sonyxperiadev / amazon-custom-resources / vpc-dependency / vpcDependency.js View on Github external
function vpcDependency(properties, callback) {
  if (!properties.VpcName)
    callback("VpcName not specified");

  var aws = require("aws-sdk");
  var ec2 = new aws.EC2();

  var responseData = {};
  console.log('vpcDependency', properties);
  ec2.describeVpcs({}, function(err, data) {
    console.log('describeVpcs', err, data);
    if (err)
      return callback(err);

    var vpcs = data.Vpcs;
    var matching = vpcs.filter(function(vpc) {
      if (properties.VpcName === 'default') {
        return vpc.IsDefault
      } else {
        var matchingTags = vpc.Tags.filter(function(tag) {
          return tag.Key === 'Name' && tag.Value === properties.VpcName;
        });
github EpistasisLab / pennai / dockers / awsm.js View on Github external
'use strict';
var fs = require('fs');
var AWS = require('aws-sdk');
AWS.config.update({
    region: 'us-east-2'
});
var Promise = require('q');
//launching containers and clusters
var ecs = new AWS.ECS({
    apiVersion: '2014-11-13'
});
//launching instances that belong to clusters
var ec2 = new AWS.EC2();
//our default image
var ImageId = 'ami-7f735a1a';
//our default instance
var InstanceType = 'm4.large';
//
var basedir = '/share/devel/pennai'
//


//shut down the cluster
exports.stopCluster = function(forumName) {
    var deferred = Promise.defer();
    var clusterName = 'c' + forumName
    console.log('stopping ' + clusterName);
    var params = {
        cluster: clusterName,
github Coalfire-Research / npk / terraform / lambda_functions / spot_monitor / main.js View on Github external
var getSpotFleetInstances = function(region, spotFleetRequestId) {
	var ec2 = new aws.EC2({region: region});

	return new Promise((success, failure) => {
		ec2.describeSpotFleetInstances({
			SpotFleetRequestId: spotFleetRequestId
		}, function(err, data) {
			if (err) {
				return failure(cb("Failed retrieving spot fleet information: " + err));
			}

			knownSpotFleetRequests[spotFleetRequestId].ActiveInstances = data.ActiveInstances;

			return success(data.ActiveInstances);
		});
	});
};
github manojlds / ebs-snapshot-lambda / lambda / ebs.js View on Github external
var utils = require('./utils');

var Promise = require('bluebird');
var AWS = require('aws-sdk');
var ec2 = new AWS.EC2(utils.getRegionObject());
var config = require('./config.json');

var getPurgeDate = function(tags) {
  var purgeDate = new Date();
  purgeDate.setTime(purgeDate.getTime() + (tags['Retention'] || config.defaultRetention) * 86400000 );
  
  return utils.getDate(purgeDate);
};

var createSnapshot = function(volumeId) {
  var snapshotParams = {
    VolumeId: volumeId,
    DryRun: false
  };
  
  return ec2.createSnapshot(snapshotParams).promise();