startInstance(model) { winston.debug('[ProviderAWSEC2] startInstance: model=', model.toString()); return new Promise((resolve, reject) => { const params = { 'InstanceIds': [model.providerOpts.id], }; this._ec2.startInstances(params, (err) => { if (err) { return reject(err); } resolve(); }); }); }
_removeInstances(models) { const ids = models.map((model) => model.providerOpts.id), names = models.map((model) => model.toString()).join(','); winston.debug('[ProviderAWSEC2] removeInstances: models=', names); return new Promise((resolve, reject) => { const params = { 'InstanceIds': ids, }; this._ec2.terminateInstances(params, (err) => { if (err) { return reject(err); } return resolve(); }); }); }
}); self._ec2.runInstances(runParams, (errParams, dataRun) => { if (errParams) { return reject(errParams); }; self._ec2.createTags(tagsParams, (errTags) => { if (errTags) { return reject(errTags);
self._ec2.describeInstances({}, (err, data) => { if (err) { return reject(err);
// Get instance's details ec2.describeInstancesAsync({InstanceIds: ['i-8575a768']}) .then(data => { console.log(data.Reservations[0]) }) .catch(err => { console.log('Error') })
_checkIsRunning(cb) { const opts = {IncludeAllInstances: true, InstanceIds: [this.instanceId]}; this.ec2.describeInstanceStatus(opts, (err, data) => { if (err) return cb(err); // console.log(util.inspect(data, {depth: 5, color: true})); cb(null, data.InstanceStatuses[0].InstanceState.Name == "running"); }); }
async stop() { console.log("Requesting stop of instance"); this.stopminecraft(); return new Promise((resolve, reject) => { this.ec2.stopInstances({InstanceIds: [this.instanceId]}, (err, data) => { if (err) { reject(err); } else { resolve(data); } }); }); }
//list enis listEnis(interfaceId) { let self = this; console.log(`Retrieving ENIs in subnets ${self.subnetIds}`); let params = { Filters: [{ Name: 'subnet-id', Values: self.subnetIds }] }; if (interfaceId) { params.Filters.push({Name: 'network-interface-id', Values: [interfaceId]}); } ec2.describeNetworkInterfaces(params, self.listENIsHandler()); }
ec2.runInstancesAsync(params) .then(data => { let instanceId = data.Instances[0].InstanceId console.log("Created instance", instanceId) console.log(data.Instances[0]) let identi = Math.floor(Math.random() * (99999 - 11111 + 1) + 11111) params = {Resources: [instanceId], Tags: [ {Key: 'Name', Value: '4yopping-' + identi} ]} return ec2.createTagsAsync(params) }) .then(data => { console.log('Tag created') }) .catch(err => { console.log('Tag failed') }) .catch(err => { console.log('Could not create instance') })
console.log("Starting instance"); const start = new Date().getTime(); this.ec2.startInstances({InstanceIds: [this.instanceId]}, async (err, data) => { if (err) return reject(err);
ec2.describeImages(describeImagesParams, function(err, describeImagesResult) { if (err) { responseData = {Error: "DescribeImages call failed"};
/** * Retrieves the route tables in the specified VPC with a blocking request. * Failure triggers a SNS message to be published to the given topic. * @param {string} vpcId Previously validated VPC resource ID with a 'vpc-' prefix and either 8 or 17 character hexadecimal suffix. * @returns {object} Description of the route tables in the specified VPC. */ async function getRouteTableDescriptions(vpcId) { const params = { DryRun: false, Filters: [ { Name: 'vpc-id', Values: [vpcId], // Only evaluate route tables in the specified VPC }, ], }; const routeTableDescriptions = await ec2.describeRouteTables(params).promise() .catch((err) => { const params = { Subject: `FAILED: Describe route tables in VPC: '${vpcId}'`, Message: err.message, TopicArn: process.env.SNS_TOPIC_ARN }; sns.publish(params); }); return routeTableDescriptions; }
ec2.detachNetworkInterface({ AttachmentId: eniInfo.Attachment.AttachmentId }, (err, data) => { ec2.deleteNetworkInterface({NetworkInterfaceId: eniInfo.NetworkInterfaceId}, self.deleteEniHandler(eniInfo.NetworkInterfaceId) );
`* End: ${new Date().toISOString()}\r\n`; await ec2.createRoute(params).promise() .then(async () => { updatedCustomRouteTableCount++; `* End: ${new Date().toISOString()}\r\n`; await ec2.replaceRoute(params).promise() .then(async () => { updatedCustomRouteTableCount++;