Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
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
});
})
}
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),
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),
"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,
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;
});
'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,
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);
});
});
};
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();