本文整理汇总了Java中com.amazonaws.services.cloudformation.AmazonCloudFormationClient.createStack方法的典型用法代码示例。如果您正苦于以下问题:Java AmazonCloudFormationClient.createStack方法的具体用法?Java AmazonCloudFormationClient.createStack怎么用?Java AmazonCloudFormationClient.createStack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.cloudformation.AmazonCloudFormationClient
的用法示例。
在下文中一共展示了AmazonCloudFormationClient.createStack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.amazonaws.services.cloudformation.AmazonCloudFormationClient; //导入方法依赖的package包/类
public void execute() {
checkParams();
AmazonCloudFormationClient client = getOrCreateClient(AmazonCloudFormationClient.class);
CreateStackRequest createStackRequest = new CreateStackRequest()
.withDisableRollback(disableRollback).withOnFailure(onFailure)
.withStackName(stackName).withStackPolicyBody(stackPolicyBody)
.withStackPolicyURL(stackPolicyURL)
.withTemplateBody(templateBody).withTemplateURL(templateURL)
.withTimeoutInMinutes(timeoutInMinutes);
if (capabilities.size() > 0) {
createStackRequest.setCapabilities(capabilities);
}
if (parameters.size() > 0) {
createStackRequest.setParameters(parameters);
}
if (tags.size() > 0) {
createStackRequest.setTags(tags);
}
try {
client.createStack(createStackRequest);
System.out.println("Create stack " + stackName
+ " request submitted.");
if(waitForCreation) {
WaitForStackToReachStateTask.waitForCloudFormationStackToReachStatus(client, stackName, CREATE_COMPLETE);
}
} catch (Exception e) {
throw new BuildException(
"Could not create stack " + e.getMessage(), e);
}
}
示例2: createNetwork
import com.amazonaws.services.cloudformation.AmazonCloudFormationClient; //导入方法依赖的package包/类
@Test
@Parameters({ "networkName", "description", "publicInAccount", "regionName", "vpcStackName", "vpcName", "existingSubnet" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount,
String regionName, @Optional("it-vpc-stack") String vpcStackName, @Optional("it-vpc") String vpcName, boolean existingSubnet) {
AmazonCloudFormationClient client = new AmazonCloudFormationClient();
client.setRegion(RegionUtils.getRegion(regionName));
Map<String, Object> networkMap = new HashMap<>();
String vpcCreationJson = existingSubnet ? "public_vpc_with_subnet.json" : "public_vpc_wihout_subnet.json";
try (InputStream vpcJsonInputStream = getClass().getResourceAsStream("/cloudformation/" + vpcCreationJson)) {
String vpcCFTemplateString = IOUtils.toString(vpcJsonInputStream);
CreateStackRequest stackRequest = createStackRequest(vpcStackName, vpcName, vpcCFTemplateString);
client.createStack(stackRequest);
List<Output> outputForRequest = getOutputForRequest(vpcStackName, client);
if (existingSubnet) {
networkMap.put("vpcId", outputForRequest.get(0).getOutputValue());
networkMap.put("subnetId", outputForRequest.get(1).getOutputValue());
} else {
networkMap.put("vpcId", outputForRequest.get(1).getOutputValue());
networkMap.put("internetGatewayId", outputForRequest.get(0).getOutputValue());
}
} catch (IOException e) {
LOGGER.error("can't read vpc cloudformation template file");
throw new RuntimeException(e);
}
NetworkRequest networkRequest = new NetworkRequest();
networkRequest.setName(networkName);
networkRequest.setDescription(description);
networkRequest.setParameters(networkMap);
if (!existingSubnet) {
networkRequest.setSubnetCIDR("10.0.0.0/24");
}
networkRequest.setCloudPlatform("AWS");
String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
示例3: launch
import com.amazonaws.services.cloudformation.AmazonCloudFormationClient; //导入方法依赖的package包/类
@Override
public List<CloudResourceStatus> launch(AuthenticatedContext ac, CloudStack stack, PersistenceNotifier resourceNotifier,
AdjustmentType adjustmentType, Long threshold) throws Exception {
createKeyPair(ac, stack);
String cFStackName = cfStackUtil.getCfStackName(ac);
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName);
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
boolean existingVPC = awsNetworkView.isExistingVPC();
boolean existingSubnet = awsNetworkView.isExistingSubnet();
boolean mapPublicIpOnLaunch = isMapPublicOnLaunch(awsNetworkView, amazonEC2Client);
try {
cfClient.describeStacks(new DescribeStacksRequest().withStackName(cFStackName));
LOGGER.info("Stack already exists: {}", cFStackName);
} catch (AmazonServiceException ignored) {
CloudResource cloudFormationStack = new Builder().type(ResourceType.CLOUDFORMATION_STACK).name(cFStackName).build();
resourceNotifier.notifyAllocation(cloudFormationStack, ac.getCloudContext());
String cidr = stack.getNetwork().getSubnet().getCidr();
String subnet = isNoCIDRProvided(existingVPC, existingSubnet, cidr) ? findNonOverLappingCIDR(ac, stack) : cidr;
AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack);
ModelContext modelContext = new ModelContext()
.withAuthenticatedContext(ac)
.withStack(stack)
.withExistingVpc(existingVPC)
.withSnapshotId(getEbsSnapshotIdIfNeeded(ac, stack))
.withExistingIGW(awsNetworkView.isExistingIGW())
.withExistingSubnetCidr(existingSubnet ? getExistingSubnetCidr(ac, stack) : null)
.withExistingSubnetIds(existingSubnet ? awsNetworkView.getSubnetList() : null)
.mapPublicIpOnLaunch(mapPublicIpOnLaunch)
.withEnableInstanceProfile(awsInstanceProfileView.isEnableInstanceProfileStrategy())
.withInstanceProfileAvailable(awsInstanceProfileView.isInstanceProfileAvailable())
.withTemplate(stack.getTemplate())
.withDefaultSubnet(subnet);
String cfTemplate = cloudFormationTemplateBuilder.build(modelContext);
LOGGER.debug("CloudFormationTemplate: {}", cfTemplate);
cfClient.createStack(createCreateStackRequest(ac, stack, cFStackName, subnet, cfTemplate));
}
LOGGER.info("CloudFormation stack creation request sent with stack name: '{}' for stack: '{}'", cFStackName, ac.getCloudContext().getId());
AmazonAutoScalingClient asClient = awsClient.createAutoScalingClient(credentialView, regionName);
PollTask<Boolean> task = awsPollTaskFactory.newAwsCreateStackStatusCheckerTask(ac, cfClient, asClient, CREATE_COMPLETE, CREATE_FAILED, ERROR_STATUSES,
cFStackName);
try {
Boolean statePollerResult = task.call();
if (!task.completed(statePollerResult)) {
syncPollingScheduler.schedule(task);
}
} catch (RuntimeException e) {
throw new CloudConnectorException(e.getMessage(), e);
}
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(credentialView, regionName);
saveS3AccessRoleArn(ac, stack, cFStackName, cfClient, resourceNotifier);
saveGeneratedSubnet(ac, stack, cFStackName, cfClient, resourceNotifier);
List<CloudResource> cloudResources = getCloudResources(ac, stack, cFStackName, cfClient, amazonEC2Client, amazonASClient, mapPublicIpOnLaunch);
return check(ac, cloudResources);
}