public void prepareWar(File warFile, String versionLabel, String applicationName) { AmazonS3 s3 = new AmazonS3Client(awsCredentials); String bucketName = beanstalkClient.createStorageLocation().getS3Bucket(); String key; try { key = URLEncoder.encode(warFile.getName() + "-" + versionLabel, "UTF-8"); s3.putObject(bucketName, key, warFile); beanstalkClient.createApplicationVersion(new CreateApplicationVersionRequest() .withApplicationName(applicationName).withAutoCreateApplication(true) .withVersionLabel(versionLabel) .withSourceBundle(new S3Location(bucketName, key))); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block journal.log(Level.SEVERE, e.getMessage()); } }
@TaskAction private void createVersion() { log.fine("Creating new application version"); AWSElasticBeanstalk client = AWSElasticBeanstalkClientBuilder.standard() .withCredentials(new DefaultAWSCredentialsProviderChain()) .withRegion(awsAppRegion) .build(); client.createApplicationVersion(new CreateApplicationVersionRequest() .withApplicationName(awsAppName) .withVersionLabel(newVersion) .withDescription("") .withSourceBundle(new S3Location() .withS3Bucket(awsAppBucket) .withS3Key(archiveName)) .withProcess(false)); log.fine("Created beanstalk application version for '" + awsAppName + "' with label '" + newVersion + "'"); } }
@TaskAction public void createVersion() { // to enable conventionMappings feature String appName = getAppName(); String versionLabel = getVersionLabel(); AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class); AWSElasticBeanstalk eb = ext.getClient(); try { eb.createApplicationVersion(new CreateApplicationVersionRequest() .withApplicationName(appName) .withVersionLabel(versionLabel) .withSourceBundle(new S3Location(getBucketName(), getKey()))); getLogger().info("version " + versionLabel + " @ " + appName + " created"); } catch (AmazonServiceException e) { if (!e.getMessage().contains("already exists.")) { throw e; } getLogger().warn("version " + versionLabel + " @ " + appName + " already exists."); } } }
@Override public boolean perform() { log("Creating application version %s for application %s for path %s", getVersionLabel(), c.config.getApplicationName(), getS3ObjectPath()); CreateApplicationVersionRequest cavRequest = new CreateApplicationVersionRequest() .withApplicationName(c.config.getApplicationName()) .withAutoCreateApplication(true) .withSourceBundle(new S3Location(c.config.getBucketName(), getObjectKey())) .withVersionLabel(getVersionLabel()) .withDescription(getVersionDescription()); final CreateApplicationVersionResult result = getAwseb().createApplicationVersion(cavRequest); log("Created version: %s", result.getApplicationVersion().getVersionLabel()); return false; } }