[英]Building Elastic Beanstalk with Node.js SDK
有沒有人用 AWS javascript sdk 創建過彈性 beanstalk 應用程序? 我已經能夠使用 grunt 更新現有的應用程序,效果非常好。 但是作為持續集成/持續部署項目的一部分,我們還希望在應用程序不存在時創建它。 我發現文檔令人困惑,並且以 AWS 的慣常方式,缺乏任何類型的有凝聚力的示例,比如“做這個,然后這個”。 如果有人這樣做並且可以為我指明正確的方向,那將是一個很大的幫助。 目前,我不確定這是單步還是多步過程。
所以,這里有一個基本的節點包來構建一個應用程序。 我已經上傳了一個基本的 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
});
}
});
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.