Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building Elastic Beanstalk with Node.js SDK

Has anyone created an elastic beanstalk application with the AWS javascript sdk? I've been able to update existing applications using grunt, that works really well. But as part of a continuous integration/continuous deployment project, we want to also create the app when it's not there. I find the documentation confusing, and in AWS's usual fashion, lacking in any kind of cohesive examples, that say, "do this, then this." If anyone has done this and can point me in the right direction, that would be a great help. At this point in time, I'm not sure whether it's a single step or multi step process.

like image 883
CargoMeister Avatar asked Feb 12 '26 18:02

CargoMeister


1 Answers

So, here's a basic node package to build an app. I have uploaded a basic API app as a zip file, it doesn't much of anything. The idea is that once it's created, I can then update it using a grunt script - there are a couple of very good grunt modules that will do that, once it's created. But the initial creation was missing. Easy enough to add on more parameters to this now, too.

 var applicationName = process.argv[2];
 var environmentName = process.argv[3];
 var regionName = process.argv[4];

 var AWS = require('aws-sdk');
 AWS.config.update({region: regionName});

 var applicationParams = {
   ApplicationName: applicationName
 };

 var environmentParams =
 {
     ApplicationName: applicationName, /* required */
     EnvironmentName: environmentName, /* required */
     VersionLabel: 'initial',
     SolutionStackName: "64bit Amazon Linux 2015.03 v1.4.4 running     Node.js",
     CNAMEPrefix: applicationName,
     Tier:
     {
         Version: " ",
         Type: "Standard",
         Name: "WebServer"
     },
     OptionSettings:
     [
         {
             Namespace: 'aws:elasticbeanstalk:environment',
             OptionName: 'EnvironmentType',
             Value: 'SingleInstance'
         },
         {
             Namespace: 'aws:autoscaling:launchconfiguration',
             OptionName: 'EC2KeyName',
             Value: 'MyPemFile'
         },
         {
             Namespace: 'aws:autoscaling:launchconfiguration',
             OptionName: 'IamInstanceProfile',
             Value: 'aws-elasticbeanstalk-ec2-role'
         },
         {
             Namespace: 'aws:autoscaling:launchconfiguration',
             OptionName: 'InstanceType',
             Value: 't1.micro'
         }
     ],
  };

 var versionParams =
 {
     ApplicationName: applicationName, /* required */
     VersionLabel: 'initial', /* required */
     AutoCreateApplication: true,
     SourceBundle:
     {
         S3Bucket: 'beanstalk-test-ff',
         S3Key: 'test-app.zip'
     }
 };

 var elasticbeanstalk = new AWS.ElasticBeanstalk();

 elasticbeanstalk.createApplication(applicationParams, function(err, data)
 {
     console.log('Creating application');
     console.log(data);
     if (err)
     {
         if (err.message.indexOf("already exists") > -1)
         {
             console.log('Application already exists, continuing on');
         }
         else
         {
             console.log(err,err.stack); // an error occurred
         }
     }
     else
     {
         elasticbeanstalk.createApplicationVersion(versionParams, function(err, data)
         {
             console.log('Creating application version....');
             console.log(data);

             if (err) console.log(err, err.stack); // an error occurred

             else
             {
                 elasticbeanstalk.createEnvironment(environmentParams, function(err, data)
                 {
                     console.log('Creating application environment....');
                     console.log(data);
                     if (err) console.log(err, err.stack); // an error occurred

                 });
             }
         });
     }
 });
like image 190
CargoMeister Avatar answered Feb 15 '26 11:02

CargoMeister