我需要从AWS SDK for Java克隆Elastic Beanstalk环境。
我找到this解答如何创建环境,但我找不到任何示例或文档来说明如何克隆环境。
我为clone
找到了CreateEnvironmentRequest
方法,但根据documentation,它克隆了CreateEnvironmentRequest
对象,而不是环境。
答案 0 :(得分:2)
已经为此打开了issue,因为现在无法从sdk进行克隆操作。如果您有兴趣,可能需要重新打开故障单并提供理由。
另一种可能性是从Java调用eb
cli来运行环境的克隆。
答案 1 :(得分:2)
好吧,你无法使用Java SDK for AWS完全克隆环境,我的方法是每次只创建一个新环境,你可以这样做:
将您的部署文件(war,zip)上传到S3
为您的部署创建一个链接到以前上传的文件的版本
private CreateApplicationVersionRequest createApplicationVersion() {
return new CreateApplicationVersionRequest()
.withApplicationName("The app name")
.withAutoCreateApplication(true)
.withSourceBundle(new S3Location("bucket_name", deployedArtifactId))
.withVersionLabel("a number for the version");
}
您去寻找最新版本的堆栈
private void getLatestStackSolutionVersion() {
ListAvailableSolutionStacksResult response = beanstalkClient.listAvailableSolutionStacks();
for (int i = 0; i < response.getSolutionStacks().size(); i++) {
if (response.getSolutionStacks().get(i).contains("Java 8") {
stackName = response.getSolutionStacks().get(i);
break;
}
}
}
配置环境,系统属性和所有内容的属性。
private Collection<ConfigurationOptionSetting> setEnvironmentProperties() {
Collection<ConfigurationOptionSetting> configurationOptionSettings = new HashSet<>();
configurationOptionSettings.add(new ConfigurationOptionSetting("aws:autoscaling:launchconfiguration", "InstanceType", "t2.medium"));
configurationOptionSettings.add(new ConfigurationOptionSetting("aws:ec2:vpc", "VPCId","thevpcid");
configurationOptionSettings.add(new ConfigurationOptionSetting("aws:ec2:vpc", "Subnets", "thesubnets");
configurationOptionSettings.add(new ConfigurationOptionSetting("aws:ec2:vpc", "ELBSubnets", "theelbsubnets");
configurationOptionSettings.add(new ConfigurationOptionSetting("aws:elasticbeanstalk:application:environment", "ANOTHER_PROPERTY", "a value"));
return configurationOptionSettings;
}
创建一切准备就绪的环境。
public void deployCreatingEnvironment() {
getLatestStackSolutionVersion();
beanstalkClient.createApplicationVersion(createApplicationVersion());
beanstalkClient.createEnvironment(setupNewEnvironment());
}
瞧!这就像每次克隆一样,希望这对你有用。