Apolak sample script

by sberube

JavaScript

/* 
 * Amazon EC2 Instance Deployment Script 
 * @displayName: Amazon EC2 Instance Deployment
 * @description: Using this script will require on your component a new property called amazonInstanceId.
 * @outputs: amazonInstanceId
 */

(function (context) {
  // context.subscriptionId = The users subsription ID
  // context.selectedResourceProviderId = The selected resource provider chosen
  // context.resourceSubscriptionId = Resource Subscription ID
  // context.serviceInstanceId = The users service instance ID 

  var amazonCLIPath = 'c:/tools/amazon/awscli/aws/exe';

  // These may not be needed as they are part of awscli directly.
  var providerHostname = CSAIntegrationHelper.getProviderHostname(context.selectedResourceProviderId);
  var providerPort = CSAIntegrationHelper.getProviderPort(context.selectedResourceProviderId);
  var providerUsername = CSAIntegrationHelper.getProviderUsername(context.selectedResourceProviderId);
  var providerPassword = CSAIntegrationHelper.getProviderPassword(context.selectedResourceProviderId);

  // Read required inputs from the resource provider
  var awsAccessKeyId = CSAIntegrationHelper.getPropertyForProvider(context.selectedResourceProviderId, 'accessKeyId'); 
  var awsSecretAccessKey = CSAIntegrationHelper.getPropertyForProvider(context.selectedResourceProviderId,'secretAccessKey');
  var awsRegionName = CSAIntegrationHelper.getPropertyForProvider(context.selectedResourceProviderId,'region');

  // Read required inputs from the component
  var amiLd = CSAIntegrationHelper.getPropertyFromComponent(context.componentId, 'amiLd');
  var instanceType = CSAIntegrationHelper.getPropertyFromComponent(context.componentId,'instanceType');
  var securityGroup = CSAIntegrationHelper.getPropertyFromComponent(context.componentId,'securityGroup');

  // Execute Command
  var result = CSAIntegrationHelper.runCommand(amazonCliPath, 'ec2 run-instances --image-id ' + amiLd + ' --count 1 --instance-type ' + instanceType + ' --key-name ' +...