List of usage examples for com.amazonaws.services.cloudformation AmazonCloudFormationClient AmazonCloudFormationClient
AmazonCloudFormationClient(AwsSyncClientParams clientParams)
From source file:jp.buyee.glover.KinesisConnectorExecutor.java
License:Open Source License
/** * Helper method to create Elasticsearch cluster at set correct endpoint. *//*from ww w . j a v a 2 s . c o m*/ private void createElasticsearchCluster() { // Create stack if not already up AmazonCloudFormation cloudFormationClient = new AmazonCloudFormationClient(config.AWS_CREDENTIALS_PROVIDER); cloudFormationClient.setRegion(RegionUtils.getRegion(config.REGION_NAME)); CloudFormationUtils.createStackIfNotExists(cloudFormationClient, config); // Update the elasticsearch endpoint to use endpoint in created cluster AmazonEC2 ec2Client = new AmazonEC2Client(config.AWS_CREDENTIALS_PROVIDER); ec2Client.setRegion(RegionUtils.getRegion(config.REGION_NAME)); config.ELASTICSEARCH_ENDPOINT = EC2Utils.getEndpointForFirstActiveInstanceWithTag(ec2Client, EC2_ELASTICSEARCH_FILTER_NAME, EC2_ELASTICSEARCH_FILTER_VALUE); if (config.ELASTICSEARCH_ENDPOINT == null || config.ELASTICSEARCH_ENDPOINT.isEmpty()) { throw new RuntimeException("Could not find active Elasticsearch endpoint from cluster."); } }
From source file:org.springframework.cloud.aws.context.config.annotation.ContextStackConfiguration.java
License:Apache License
@Bean @ConditionalOnMissingAmazonClient(AmazonCloudFormation.class) public AmazonCloudFormation amazonCloudFormation() { AmazonCloudFormationClient formationClient; if (this.credentialsProvider != null) { formationClient = new AmazonCloudFormationClient(this.credentialsProvider); } else {/*from ww w. j a v a 2 s .c om*/ formationClient = new AmazonCloudFormationClient(); } if (this.regionProvider != null) { formationClient.setRegion(this.regionProvider.getRegion()); } return formationClient; }
From source file:org.springframework.cloud.stream.app.aws.AwsIntegrationTestStackRule.java
License:Apache License
@Override protected void before() throws Throwable { try {// w w w . ja va 2 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; } } }
From source file:org.terracotta.TerracottaCloudFormationSample.java
License:Open Source License
@org.junit.BeforeClass public static void createStack() throws Exception { /*/*www. ja v a 2 s .c o m*/ * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this * sample. * http://aws.amazon.com/security-credentials */ amazonCloudFormationClient = new AmazonCloudFormationClient(new PropertiesCredentials( TerracottaCloudFormationSample.class.getResourceAsStream("/AwsCredentials.properties"))); System.out.println("================================"); System.out.println("Terracotta CloudFormation Sample"); System.out.println("================================\n"); try { // Create a stack CreateStackRequest createRequest = new CreateStackRequest(); createRequest.setStackName(stackName); createRequest.setTemplateBody(convertStreamToString( TerracottaCloudFormationSample.class.getResourceAsStream("/TerracottaServerArray.template"))); Parameter parameter = new Parameter(); parameter.setParameterKey("KeyName"); parameter.setParameterValue(keyChainName); List parameters = new ArrayList(); parameters.add(parameter); createRequest.setParameters(parameters); System.out.println("Creating a stack called " + createRequest.getStackName() + "."); amazonCloudFormationClient.createStack(createRequest); // Wait for stack to be created // Note that you could use SNS notifications on the CreateStack call to track the progress of the stack creation System.out.println("Stack creation completed, the stack " + stackName + " completed with " + waitForCompletion(amazonCloudFormationClient, stackName)); // Show all the stacks for this account along with the resources for each stack for (Stack stack : amazonCloudFormationClient.describeStacks(new DescribeStacksRequest()).getStacks()) { System.out.println( "Stack : " + stack.getStackName() + " [" + stack.getStackStatus().toString() + "]"); DescribeStackResourcesRequest stackResourceRequest = new DescribeStackResourcesRequest(); stackResourceRequest.setStackName(stack.getStackName()); for (StackResource resource : amazonCloudFormationClient .describeStackResources(stackResourceRequest).getStackResources()) { System.out.format(" %1$-40s %2$-25s %3$s\n", resource.getResourceType(), resource.getLogicalResourceId(), resource.getPhysicalResourceId()); } } // Lookup a resource by its logical name DescribeStackResourcesRequest logicalNameResourceRequest = new DescribeStackResourcesRequest(); logicalNameResourceRequest.setStackName(stackName); logicalNameResourceRequest.setLogicalResourceId(logicalResourceName); System.out.format("Looking up resource name %1$s from stack %2$s\n", logicalNameResourceRequest.getLogicalResourceId(), logicalNameResourceRequest.getStackName()); for (StackResource resource : amazonCloudFormationClient .describeStackResources(logicalNameResourceRequest).getStackResources()) { System.out.format(" %1$-40s %2$-25s %3$s\n", resource.getResourceType(), resource.getLogicalResourceId(), resource.getPhysicalResourceId()); } //deleteStack } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS CloudFormation, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS CloudFormation, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }