2014-11-25 82 views
0

任何人都可以幫助我或使用Java程序創建Aws彈性beanstalk環境的任何來源,並介紹我們的應用程序嗎?如何使用java sdk創建AWS Elastic Beanstalk環境?

預先感謝您。

+0

您是否嘗試創建環境並使用java代碼進行部署,或者您是否嘗試以任何方式將java代碼部署到環境中? – 2014-11-25 18:13:16

回答

2

您也可以下載AWS Java SDK的here。這也是在Maven倉庫:

Maven的:

<dependency> 
    <groupId>com.amazonaws</groupId> 
    <artifactId>aws-java-sdk</artifactId> 
    <version>1.9.7</version> 
</dependency> 

搖籃:

'com.amazonaws:aws-java-sdk:1.9.7' 

現在,到使用SDK。你可能想在getting started with the aws sdk.

讀了下面是一些非常淡化代碼,讓你開始:

import com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalkClient; 
import com.amazonaws.services.elasticbeanstalk.model.*; 
import com.amazonaws.services.s3.AmazonS3Client; 
import com.amazonaws.services.s3.model.PutObjectRequest; 

import java.io.File; 

public class AwsTest { 

    public static void main(String[] args) { 

     AWSElasticBeanstalkClient eb = new AWSElasticBeanstalkClient(); 

     // Create Application 
     CreateApplicationRequest request = new CreateApplicationRequest("myAppName"); 
     eb.createApplication(request); 

     // Create Environment 
     CreateEnvironmentRequest envRequest = new CreateEnvironmentRequest("myAppName", "env-name"); 
     envRequest.setSolutionStackName("64bit Amazon Linux 2014.09 v1.0.9 running Tomcat 7 Java 7"); 
     envRequest.setVersionLabel("application Version"); 
     eb.createEnvironment(envRequest); 

     // Deploy code 
     CreateStorageLocationResult location = eb.createStorageLocation(); 
     String bucket = location.getS3Bucket(); 
     File file = new File("myapp.zip"); 
     PutObjectRequest object = new PutObjectRequest(bucket, "myapp.zip", file); 
     new AmazonS3Client().putObject(object); 

     CreateApplicationVersionRequest versionRequest = new CreateApplicationVersionRequest(); 
     versionRequest.setVersionLabel("myversion"); 
     versionRequest.setApplicationName("myAppName"); 
     S3Location s3 = new S3Location(bucket, "myapp.zip"); 
     versionRequest.setSourceBundle(s3); 

     UpdateEnvironmentRequest updateRequest = new UpdateEnvironmentRequest(); 
     updateRequest.setVersionLabel("myversion"); 
     eb.updateEnvironment(updateRequest); 

    } 
} 
0

有本條所指的一小段代碼,在上面給出的代碼丟失,

CreateApplicationVersionRequest versionRequest = new CreateApplicationVersionRequest(); 
     versionRequest.setVersionLabel("myversion"); 
     versionRequest.setApplicationName("myAppName"); 
     S3Location s3 = new S3Location(bucket, "myapp.zip"); 
     versionRequest.setSourceBundle(s3); 

您需要新增eb.createApplicationVersion(versionRequest);以創建包含自己的源文件的新版本。只有這樣您才能將新版本部署到環境的運行實例。

相關問題