Example usage for com.amazonaws.services.cloudformation.model OnFailure DELETE

List of usage examples for com.amazonaws.services.cloudformation.model OnFailure DELETE

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudformation.model OnFailure DELETE.

Prototype

OnFailure DELETE

To view the source code for com.amazonaws.services.cloudformation.model OnFailure DELETE.

Click Source Link

Usage

From source file:org.springframework.cloud.stream.app.aws.AwsIntegrationTestStackRule.java

License:Apache License

@Override
protected void before() throws Throwable {
    try {//  www .  ja v  a2  s. com
        String awsCredentialsDir = System.getProperty("aws.credentials.path");
        File awsCredentialsFile = new File(awsCredentialsDir, "aws.credentials.properties");
        Properties awsCredentials = new Properties();
        awsCredentials.load(new FileReader(awsCredentialsFile));
        String accessKey = awsCredentials.getProperty("cloud.aws.credentials.accessKey");
        String secretKey = awsCredentials.getProperty("cloud.aws.credentials.secretKey");
        this.cloudFormation = new AmazonCloudFormationClient(new BasicAWSCredentials(accessKey, secretKey));

        YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
        yamlPropertiesFactoryBean.setResources(new ClassPathResource("application.yml"));
        Properties applicationProperties = yamlPropertiesFactoryBean.getObject();

        this.stackName = applicationProperties.getProperty("cloud.aws.stack.name");

        after();

        ClassPathResource stackTemplate = new ClassPathResource("AwsIntegrationTestTemplate.json");
        String templateBody = FileCopyUtils.copyToString(new InputStreamReader(stackTemplate.getInputStream()));

        this.cloudFormation.createStack(new CreateStackRequest().withTemplateBody(templateBody)
                .withOnFailure(OnFailure.DELETE).withStackName(this.stackName));

        waitForCompletion();

        System.setProperty("cloud.aws.credentials.accessKey", accessKey);
        System.setProperty("cloud.aws.credentials.secretKey", secretKey);
    } catch (Exception e) {
        if (!(e instanceof AssumptionViolatedException)) {
            Assume.assumeTrue("Can't perform AWS integration test because of: " + e.getMessage(), false);
        } else {
            throw e;
        }
    }
}