src/main/java/com/digitalglobe/util/maven/plugin/CloudFormationDeployMavenPlugin.java
/**
     * Use this method to execute a template.  Replace input parameters; execute template and extract output parameters.
     *
     * @param readOnly is a flag to signal if the template is used to read the output parameters without update.
     * @param templateUrl contains the URL to the template to execute.
     * @param stackParameterFilePath is the file path to the parameter file to use with the template.
     * @param cfAsyncClient is the cloud formation client to use when performing the update or create stack.
     * @param s3client is a client to use when overriding the master stack artifact.
     * @param stackName is the name of the stack to create when executing the cloud formation template.
     * @param condition is the name of the condition for the template.
     * @param deploymentArtifactRegEx is the regular expression to use to find the deployment file.
     * @param credentials is the set of credential to use for the system manager.
     * @param inputParameters are the input parameters to substitute before executing the template.
     * @param outputParameters are the output parameters from this and previous template operations.
     * @param outputParameterMappings are the mappings to apply to output parameters.
     * @param cliCommandOutputParameterMappings is a set of CLI command to run to retrieve output parameters.
     * @param checkCondition is a condition to check against the value of an output parameter.
     * @param region is the region to use for executing templates and storing parameters.
     * @throws IOException when the parameter file can't be read from.
     * @throws InterruptedException when the operating system interrupts the execution of a CLI Command.
     * @throws NoSuchAlgorithmException when it to calculate a file hash.
     * @throws MojoExecutionException when the stack couldn't execute for a reason other then no changes.
     */
Use this method to execute a template.  Replace input parameters; execute template and extract output parameters.
@param readOnly is a flag to signal if the template is used to read the output parameters without update.
@param templateUrl contains the URL to the template to execute.
@param stackParameterFilePath is the file path to the parameter file to use with the template.
@param cfAsyncClient is the cloud formation client to use when performing the update or create stack.
@param s3client is a client to use when overriding the master stack artifact.
@param stackName is the name of the stack to create when executing the cloud formation template.
@param condition is the name of the condition for the template.
@param deploymentArtifactRegEx is the regular expression to use to find the deployment file.
@param credentials is the set of credential to use for the system manager.
@param inputParameters are the input parameters to substitute before executing the template.
@param outputParameters are the output parameters from this and previous template operations.
@param outputParameterMappings are the mappings to apply to output parameters.
@param cliCommandOutputParameterMappings is a set of CLI command to run to retrieve output parameters.
@param checkCondition is a condition to check against the value of an output parameter.
@param region is the region to use for executing templates and storing parameters.
@throws IOException when the parameter file can't be read from.
@throws InterruptedException when the operating system interrupts the execution of a CLI Command.
@throws NoSuchAlgorithmException when it to calculate a file hash.
@throws MojoExecutionException when the stack couldn't execute for a reason other then no changes.
Use this method to execute a template . Replace input parameters ; execute template and extract output parameters . @param readOnly is a flag to signal if the template is used to read the output parameters without update . @param templateUrl contains the URL to the template to execute . @param stackParameterFilePath is the file path to the parameter file to use with the template . @param cfAsyncClient is the cloud formation client to use when performing the update or create stack . @param s3client is a client to use when overriding the master stack artifact . @param stackName is the name of the stack to create when executing the cloud formation template . @param condition is the name of the condition for the template . @param deploymentArtifactRegEx is the regular expression to use to find the deployment file . @param credentials is the set of credential to use for the system manager . @param inputParameters are the input parameters to substitute before executing the template . @param outputParameters are the output parameters from this and previous template operations . @param outputParameterMappings are the mappings to apply to output parameters . @param cliCommandOutputParameterMappings is a set of CLI command to run to retrieve output parameters . @param checkCondition is a condition to check against the value of an output parameter . @param region is the region to use for executing templates and storing parameters . @throws IOException when the parameter file can ' t be read from . @throws InterruptedException when the operating system interrupts the execution of a CLI Command . @throws NoSuchAlgorithmException when it to calculate a file hash . @throws MojoExecutionException when the stack couldn ' t execute for a reason other then no changes .
private void ExecuteTemplate(Boolean readOnly, String templateUrl, String stackParameterFilePath,
                                 CloudFormationAsyncClient cfAsyncClient,
                                 S3Client s3client, String stackName, String condition,
                                 String deploymentArtifactRegEx, AwsCredentialsProvider credentials,
                                 StackInputParameter[] inputParameters, Map<String, String> outputParameters,
                                 StackOutputParameterMapping[] outputParameterMappings,
                                 CliCommandOutputParameterMapping[] cliCommandOutputParameterMappings,
                                 ParameterValueCheckCondition checkCondition, String region)
            throws IOException, InterruptedException, NoSuchAlgorithmException, MojoExecutionException {
        boolean cloudFormationExists = isTemplatePreviouslyDeployed(cfAsyncClient, stackName);
        String auditString;
        Predicate<StackInputParameter> sha = param -> param.parameterName.equals("CodeSHA256");
        if(readOnly) {
            auditString = (cloudFormationExists ? ("Reading the output from " + stackName + ".\n") :
                    stackName + " is not required for for this deployment.\n");
        } else auditString = (cloudFormationExists ? "Updating" : "Creating") + " the CloudFormation Stack (" +
                stackName + ").\n";
        if(shouldExecuteStack(condition) && evaluateCheckCondition(checkCondition, outputParameters)) {
            audit.write(auditString);
            System.out.print(auditString);
            if(!readOnly) {
                storeDeploymentArtifact(s3client, deploymentArtifactRegEx, outputParameters);
                Parameter[] parameters = getInputParameters(stackParameterFilePath, credentials, inputParameters,
                        outputParameters, region);
                if((inputParameters != null) && Arrays.stream(inputParameters).anyMatch(sha)) Thread.sleep(10000);
                if (cloudFormationExists) {
                    DetectAndProcessStackChanges(templateUrl, cfAsyncClient, stackName, parameters);
                } else {
                    createStack(stackName, templateUrl, cfAsyncClient, parameters);
                    audit.write("Stack Finished.\n");
                    System.out.println("Stack Finished.");
                }
            }
            System.out.println();
            SsmClient ssmClient;
            if(region != null) ssmClient = (credentials != null) ?
                    new ClientBuilder<SsmClient>().withRegion(region).build(ssmBuilder, credentials) :
                    new ClientBuilder<SsmClient>().withRegion(region).build((ssmBuilder));
            else ssmClient = (credentials != null) ?
                    new ClientBuilder<SsmClient>().build(ssmBuilder, credentials) :
                    new ClientBuilder<SsmClient>().build(ssmBuilder);
            processOutputParameters(cfAsyncClient, stackName, credentials, ssmClient, outputParameters,
                    outputParameterMappings, region);
            processCommandOutputParameters(credentials, ssmClient, outputParameters,
                    cliCommandOutputParameterMappings, region);
        } else {
            audit.write(stackName + " is not required.\n");
            System.out.println( stackName + " is not required.");
            System.out.println();
        }
    }
private void ExecuteTemplate ( Boolean readOnly , String templateUrl , String stackParameterFilePath , CloudFormationAsyncClient cfAsyncClient , S3Client s3client , String stackName , String condition , String deploymentArtifactRegEx , AwsCredentialsProvider credentials , StackInputParameter [ ] inputParameters , Map < String , String > outputParameters , StackOutputParameterMapping [ ] outputParameterMappings , CliCommandOutputParameterMapping [ ] cliCommandOutputParameterMappings , ParameterValueCheckCondition checkCondition , String region ) throws IOException , InterruptedException , NoSuchAlgorithmException , MojoExecutionException { boolean cloudFormationExists = isTemplatePreviouslyDeployed ( cfAsyncClient , stackName ) ; String auditString ; Predicate < StackInputParameter > sha = param -> param . parameterName . equals ( "CodeSHA256" ) ; if ( readOnly ) { auditString = ( cloudFormationExists ? ( "Reading the output from " + stackName + ".\n" ) : stackName + " is not required for for this deployment.\n" ) ; } else auditString = ( cloudFormationExists ? "Updating" : "Creating" ) + " the CloudFormation Stack (" + stackName + ").\n" ; if ( shouldExecuteStack ( condition ) && evaluateCheckCondition ( checkCondition , outputParameters ) ) { audit . write ( auditString ) ; System . out . print ( auditString ) ; if ( ! readOnly ) { storeDeploymentArtifact ( s3client , deploymentArtifactRegEx , outputParameters ) ; Parameter [ ] parameters = getInputParameters ( stackParameterFilePath , credentials , inputParameters , outputParameters , region ) ; if ( ( inputParameters != null ) && Arrays . stream ( inputParameters ) . anyMatch ( sha ) ) Thread . sleep ( 10000 ) ; if ( cloudFormationExists ) { DetectAndProcessStackChanges ( templateUrl , cfAsyncClient , stackName , parameters ) ; } else { createStack ( stackName , templateUrl , cfAsyncClient , parameters ) ; audit . write ( "Stack Finished.\n" ) ; System . out . println ( "Stack Finished." ) ; } } System . out . println ( ) ; SsmClient ssmClient ; if ( region != null ) ssmClient = ( credentials != null ) ? new ClientBuilder < SsmClient > ( ) . withRegion ( region ) . build ( ssmBuilder , credentials ) : new ClientBuilder < SsmClient > ( ) . withRegion ( region ) . build ( ( ssmBuilder ) ) ; else ssmClient = ( credentials != null ) ? new ClientBuilder < SsmClient > ( ) . build ( ssmBuilder , credentials ) : new ClientBuilder < SsmClient > ( ) . build ( ssmBuilder ) ; processOutputParameters ( cfAsyncClient , stackName , credentials , ssmClient , outputParameters , outputParameterMappings , region ) ; processCommandOutputParameters ( credentials , ssmClient , outputParameters , cliCommandOutputParameterMappings , region ) ; } else { audit . write ( stackName + " is not required.\n" ) ; System . out . println ( stackName + " is not required." ) ; System . out . println ( ) ; } }
Use this method to execute a template.
Use this method to execute a template .
// Determine if the stack exists. // Determine if the template is required in this deployment. // Continue processing the template. // Read the stack parameters. // Check to see if the stack has changes to process. // Create or update the Stack. // Add output parameters from the stack run and optionally save them to the Parameter Store.