【问题标题】:Building Elastic Beanstalk with Node.js SDK使用 Node.js SDK 构建 Elastic Beanstalk
【发布时间】:2015-10-19 17:38:44
【问题描述】:

是否有人使用 AWS javascript sdk 创建了弹性 beanstalk 应用程序?我已经能够使用 grunt 更新现有的应用程序,效果非常好。但作为持续集成/持续部署项目的一部分,我们还想在应用程序不存在时创建它。我发现文档令人困惑,并且按照 AWS 的惯常方式,缺少任何类型的有凝聚力的示例,即“先这样做,然后再这样做”。如果有人这样做并且可以为我指明正确的方向,那将是一个很大的帮助。在这个时间点,我不确定它是单步过程还是多步过程。

【问题讨论】:

    标签: node.js amazon-web-services amazon-elastic-beanstalk aws-sdk


    【解决方案1】:

    所以,这是构建应用程序的基本节点包。我已经上传了一个基本的 API 应用程序作为一个 zip 文件,它什么都不是。这个想法是,一旦创建它,​​我就可以使用 grunt 脚本对其进行更新——一旦创建,有几个非常好的 grunt 模块可以做到这一点。但最初的创作缺失了。现在也很容易添加更多参数。

     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
    
                     });
                 }
             });
         }
     });
    

    【讨论】:

      猜你喜欢
      • 2015-01-22
      • 2014-12-25
      • 2016-10-16
      • 2017-07-29
      • 2020-05-19
      • 2017-04-07
      • 1970-01-01
      • 2019-08-10
      • 2017-10-05
      相关资源
      最近更新 更多