List of usage examples for com.amazonaws.services.cloudformation.model Capability CAPABILITY_IAM
Capability CAPABILITY_IAM
To view the source code for com.amazonaws.services.cloudformation.model Capability CAPABILITY_IAM.
Click Source Link
From source file:br.com.ingenieux.mojo.cloudformation.PushStackMojo.java
License:Apache License
private CreateStackResult createStack() throws Exception { CreateStackRequest req = new CreateStackRequest().withStackName(stackName) .withCapabilities(Capability.CAPABILITY_IAM); if (null != this.destinationS3Uri) { req.withTemplateURL(generateExternalUrl(this.destinationS3Uri)); } else {//from w ww. j av a 2 s. co m req.withTemplateBody(templateBody); } req.withNotificationARNs(notificationArns); req.withParameters(parameters); req.withResourceTypes(resourceTypes); req.withDisableRollback(disableRollback); req.withTags(tags); req.withTimeoutInMinutes(timeoutInMinutes); return getService().createStack(req); }
From source file:br.com.ingenieux.mojo.cloudformation.PushStackMojo.java
License:Apache License
private UpdateStackResult updateStack() throws Exception { UpdateStackRequest req = new UpdateStackRequest().withStackName(stackName) .withCapabilities(Capability.CAPABILITY_IAM); if (null != this.destinationS3Uri) { req.withTemplateURL(generateExternalUrl(this.destinationS3Uri)); } else {/*from www. j a v a2s. c om*/ req.withTemplateBody(templateBody); } req.withNotificationARNs(notificationArns); req.withParameters(parameters); req.withResourceTypes(resourceTypes); req.withTags(tags); try { return getService().updateStack(req); } catch (AmazonServiceException exc) { if ("No updates are to be performed.".equals(exc.getErrorMessage())) { return null; } throw exc; } }
From source file:com.github.kaklakariada.aws.sam.service.CloudformationService.java
License:Open Source License
public String createChangeSet(String changeSetName, String stackName, ChangeSetType changeSetType, String templateBody, Collection<Parameter> parameters) { logger.info("Creating change set for stack {} with name {}, type {} and parameters {}", stackName, changeSetName, changeSetType, parameters); final CreateChangeSetRequest changeSetRequest = new CreateChangeSetRequest() // .withCapabilities(Capability.CAPABILITY_IAM) // .withStackName(stackName) // .withDescription(stackName) // .withChangeSetName(changeSetName) // .withChangeSetType(changeSetType) // .withParameters(parameters).withTemplateBody(templateBody); final CreateChangeSetResult result = cloudFormation.createChangeSet(changeSetRequest); logger.info("Change set created: {}", result); return result.getId(); }
From source file:com.tvarit.plugin.AutoScalingMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().debug("Starting " + this.getClass().getSimpleName() + " execution "); final BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3Client amazonS3Client = new AmazonS3Client(awsCredentials); final MavenProject project = (MavenProject) this.getPluginContext().getOrDefault("project", null); String lambdaCodeS3Bucket = this.bucketName; if (lambdaCodeS3Key == null) { lambdaCodeS3Key = new LambdaS3BucketKeyMaker().makeKey(project); lambdaCodeS3Bucket = "tvarit"; }/*from www. ja v a 2s . com*/ AmazonCloudFormationClient amazonCloudFormationClient = new AmazonCloudFormationClient(awsCredentials); AmazonEC2Client amazonEC2Client = new AmazonEC2Client(awsCredentials); List<com.amazonaws.services.cloudformation.model.Parameter> allParams = new AsgParameterMaker().make( amazonEC2Client, amazonCloudFormationClient, project, projectName, lambdaCodeS3Key, lambdaCodeS3Bucket); final String stackName = projectName + "-asg"; if (templateUrl == null) try { templateUrl = new TemplateUrlMaker().makeUrl(project, "autoscaling.template").toString(); } catch (MalformedURLException e) { throw new MojoExecutionException( "Could not create default url for templates. Please open an issue on github.", e); } final CreateStackRequest createStackRequest = new CreateStackRequest() .withCapabilities(Capability.CAPABILITY_IAM).withStackName(stackName).withParameters(allParams) .withTemplateURL(templateUrl); final Stack stack = new StackMaker().makeStack(createStackRequest, amazonCloudFormationClient, getLog()); new S3WarUploadEventToInvokeLambdaMaker().make(amazonS3Client, bucketName, stack); getLog().info("Finished completing stack"); }
From source file:com.tvarit.plugin.InfrastructureMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().debug("Starting " + this.getClass().getSimpleName() + " execution "); getLog().warn(//from ww w. java 2 s .c o m "This goal has been deprecated and may be removed without notice. Please use the goal 'make-infrastructure' instead."); final BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); AmazonCloudFormationClient amazonCloudFormationClient = new AmazonCloudFormationClient(awsCredentials); final com.amazonaws.services.cloudformation.model.Parameter domainNameParameter = new com.amazonaws.services.cloudformation.model.Parameter() .withParameterKey("domainName").withParameterValue(this.domainName); final com.amazonaws.services.cloudformation.model.Parameter projectNameParameter = new com.amazonaws.services.cloudformation.model.Parameter() .withParameterKey("projectName").withParameterValue(this.projectName); final com.amazonaws.services.cloudformation.model.Parameter bucketNameParameter = new com.amazonaws.services.cloudformation.model.Parameter() .withParameterKey("bucketName").withParameterValue("tvarit-" + this.bucketName); final CreateStackRequest createStackRequest = new CreateStackRequest() .withCapabilities(Capability.CAPABILITY_IAM).withStackName(projectName + "-infra") .withParameters(domainNameParameter, projectNameParameter, bucketNameParameter); if (templateUrl == null) { final String template = new TemplateReader().readTemplate("/cfn-templates/vpc-infra.template"); createStackRequest.withTemplateBody(template); } else { createStackRequest.withTemplateURL(templateUrl); } new StackMaker().makeStack(createStackRequest, amazonCloudFormationClient, getLog()); getLog().info("Finished completing stack"); }
From source file:com.tvarit.plugin.NewInfrastructureMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().debug("Starting " + this.getClass().getSimpleName() + " execution "); final BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); AmazonCloudFormationClient amazonCloudFormationClient = new AmazonCloudFormationClient(awsCredentials); final com.amazonaws.services.cloudformation.model.Parameter domainNameParameter = new com.amazonaws.services.cloudformation.model.Parameter() .withParameterKey("domainName").withParameterValue(this.domainName); final com.amazonaws.services.cloudformation.model.Parameter projectNameParameter = new com.amazonaws.services.cloudformation.model.Parameter() .withParameterKey("projectName").withParameterValue(this.projectName); final com.amazonaws.services.cloudformation.model.Parameter bucketNameParameter = new com.amazonaws.services.cloudformation.model.Parameter() .withParameterKey("bucketName").withParameterValue(this.bucketName); final String template; final MavenProject project = (MavenProject) this.getPluginContext().getOrDefault("project", null); if (templateUrl == null) { try {/* w ww . j a va 2s . c om*/ templateUrl = new TemplateUrlMaker().makeUrl(project, "vpc-infra.template").toString(); } catch (MalformedURLException e) { throw new MojoExecutionException( "Could not create default url for templates. Please open an issue on github.", e); } } final CreateStackRequest createStackRequest = new CreateStackRequest() .withCapabilities(Capability.CAPABILITY_IAM).withStackName(projectName + "-infra") .withParameters(domainNameParameter, projectNameParameter, bucketNameParameter) .withTemplateURL(templateUrl); new StackMaker().makeStack(createStackRequest, amazonCloudFormationClient, getLog()); getLog().info("Finished completing stack"); }
From source file:de.taimos.pipeline.aws.cloudformation.CloudFormationStack.java
License:Apache License
public void create(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, Integer timeoutInMinutes, long pollIntervallMillis, String roleArn, String onFailure) throws ExecutionException { if ((templateBody == null || templateBody.isEmpty()) && (templateUrl == null || templateUrl.isEmpty())) { throw new IllegalArgumentException("Either a file or url for the template must be specified"); }/*from w w w.ja v a2 s . c o m*/ CreateStackRequest req = new CreateStackRequest(); req.withStackName(this.stack).withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM); req.withTemplateBody(templateBody).withTemplateURL(templateUrl).withParameters(params).withTags(tags) .withTimeoutInMinutes(timeoutInMinutes).withRoleARN(roleArn) .withOnFailure(OnFailure.valueOf(onFailure)); this.client.createStack(req); new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack, this.client.waiters().stackCreateComplete(), pollIntervallMillis); }
From source file:de.taimos.pipeline.aws.cloudformation.CloudFormationStack.java
License:Apache License
public void update(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, long pollIntervallMillis, String roleArn) throws ExecutionException { try {/*w w w . ja v a 2 s . co m*/ UpdateStackRequest req = new UpdateStackRequest(); req.withStackName(this.stack).withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM); if (templateBody != null && !templateBody.isEmpty()) { req.setTemplateBody(templateBody); } else if (templateUrl != null && !templateUrl.isEmpty()) { req.setTemplateURL(templateUrl); } else { req.setUsePreviousTemplate(true); } req.withParameters(params).withTags(tags).withRoleARN(roleArn); this.client.updateStack(req); new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack, this.client.waiters().stackUpdateComplete(), pollIntervallMillis); this.listener.getLogger().format("Updated CloudFormation stack %s %n", this.stack); } catch (AmazonCloudFormationException e) { if (e.getMessage().contains("No updates are to be performed")) { this.listener.getLogger().format("No updates were needed for CloudFormation stack %s %n", this.stack); return; } this.listener.getLogger().format("Failed to update CloudFormation stack %s %n", this.stack); throw e; } }
From source file:de.taimos.pipeline.aws.cloudformation.CloudFormationStack.java
License:Apache License
public void createChangeSet(String changeSetName, String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, long pollIntervallMillis, ChangeSetType changeSetType, String roleArn) throws ExecutionException { try {// ww w .ja va2 s . com CreateChangeSetRequest req = new CreateChangeSetRequest(); req.withChangeSetName(changeSetName).withStackName(this.stack) .withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM) .withChangeSetType(changeSetType); if (ChangeSetType.CREATE.equals(changeSetType)) { this.listener.getLogger().format("Creating CloudFormation change set %s for new stack %s %n", changeSetName, this.stack); if ((templateBody == null || templateBody.isEmpty()) && (templateUrl == null || templateUrl.isEmpty())) { throw new IllegalArgumentException("Either a file or url for the template must be specified"); } req.withTemplateBody(templateBody).withTemplateURL(templateUrl); } else if (ChangeSetType.UPDATE.equals(changeSetType)) { this.listener.getLogger().format("Creating CloudFormation change set %s for existing stack %s %n", changeSetName, this.stack); if (templateBody != null && !templateBody.isEmpty()) { req.setTemplateBody(templateBody); } else if (templateUrl != null && !templateUrl.isEmpty()) { req.setTemplateURL(templateUrl); } else { req.setUsePreviousTemplate(true); } } else { throw new IllegalArgumentException( "Cannot create a CloudFormation change set without a valid change set type."); } req.withParameters(params).withTags(tags).withRoleARN(roleArn); this.client.createChangeSet(req); new EventPrinter(this.client, this.listener).waitAndPrintChangeSetEvents(this.stack, changeSetName, this.client.waiters().changeSetCreateComplete(), pollIntervallMillis); this.listener.getLogger().format("Created CloudFormation change set %s for stack %s %n", changeSetName, this.stack); } catch (ExecutionException e) { try { if (this.changeSetExists(changeSetName) && !this.changeSetHasChanges(changeSetName)) { // Ignore the failed creation of a change set with no changes. this.listener.getLogger().format("Created empty change set %s for stack %s %n", changeSetName, this.stack); return; } } catch (Throwable throwable) { e.addSuppressed(throwable); } this.listener.getLogger().format("Failed to create CloudFormation change set %s for stack %s %n", changeSetName, this.stack); throw e; } }
From source file:de.taimos.pipeline.aws.cloudformation.stacksets.CloudFormationStackSet.java
License:Apache License
public CreateStackSetResult create(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags) { if ((templateBody == null || templateBody.isEmpty()) && (templateUrl == null || templateUrl.isEmpty())) { throw new IllegalArgumentException("Either a file or url for the template must be specified"); }//from ww w .j a v a2 s .c o m this.listener.getLogger().println("Creating stack set " + this.stackSet); CreateStackSetRequest req = new CreateStackSetRequest().withStackSetName(this.stackSet) .withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM) .withTemplateBody(templateBody).withTemplateURL(templateUrl).withParameters(params).withTags(tags); CreateStackSetResult result = this.client.createStackSet(req); this.listener.getLogger().println("Created Stack set stackSetId=" + result.getStackSetId()); return result; }