node.js - 使用 Node.js SDK 构建 Elastic Beanstalk

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

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

最佳答案

所以,这是构建应用程序的基本 Node 包。我已经以 zip 文件的形式上传了一个基本的 API 应用程序,它没有什么东西。这个想法是,一旦创建了它,我就可以使用 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

                 });
             }
         });
     }
 });

关于node.js - 使用 Node.js SDK 构建 Elastic Beanstalk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31688611/

相关文章:

Node.js v0.10.18 Mongoose 验证失败于方法 'captureStackTrace' ”

node.js - Azure 存储移动服务的读取和写入访问策略

node.js - 如何使用 Amazon EC2 实例设置用于生产的 node.js process.env 变量?

asp.net-mvc - ASP.NET Core 1.0 中的 AWS Elastic Beanstalk 环境变量

python - 将 Mac 上的 Python 从 2.7 升级到 3.6(或最新版本)以用于弹性 beantalk 客户端 AWS

ruby-on-rails - 适用于 Ruby 和 Node.JS 的 2 路加密算法,仅加密字母和数字

node.js - 在不同的机器上运行客户端和服务器

amazon-web-services - 如何在无服务器中将 aws 堆栈名称与其他字符串连接起来?

amazon-web-services - 如何知道lambda函数本身的事件源

python - Django collectstatic 命令在 AWS Elastic Beanstalk Amazon Linux 2 Python 3 平台中失败