10

I get that I can create resources using CloudFormation, and that I can also create a VPC using CloudFormation, along with the resources inside it.

Can I create a stack, using a CloudFormation template, inside a pre-existing VPC? For example, let's say that I have a VPC for my company, and there is a Services segment, some production segments (private and public), and maybe some Development segments.

I want to define each set of services - Services, production environment, Development environments - with its own CloudFormation template inside the VPC.

Can I do that?

4

4 回答 4

11

由于这没有很好地记录,而且我见过的所有示例(包括 Julio 的)都只是使用提示手动输入 VPC ID 的字符串字段,这是最好的方法。

您可以通过显示所有现有 VPC 的下拉菜单让您的模板提示您,让您选择一个。

在您的模板中使用 AWS::EC2::VPC::Id 属性:

{
  "Parameters" : {
    "VpcId" : {
      "Type" : "AWS::EC2::VPC::Id",
      "Description" : "VpcId of your existing Virtual Private Cloud (VPC)"
    }
  }
}

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html

于 2014-12-05T23:34:26.450 回答
10

是的你可以。您可以将子网 id 作为参数传递并在这些子网中创建资源,也可以将 vpc id 作为参数传递并在其中创建子网和资源。

例如,此模板将在现有 VPC 内创建 RDS 数据库: https ://s3.amazonaws.com/cloudformation-templates-us-east-1/RDS_VPC.template

于 2014-06-14T18:41:19.590 回答
0

是的你可以。另一个文件中定义的堆栈对于主 JSON 是堆栈类型的资源。当然,您必须告诉在哪里检索其他 JSON/YML 文件。

Cloudformation 并不容易,所以我建议尝试使用现有架构并逐步修改。

这个例子应该对你有所帮助。

于 2018-05-16T20:04:58.580 回答
0

有趣的是,我正要指出它应该是 List<> 但我对两者都进行了测试,并且您的方法也有效。

"VpcId" : {
  "Type" : "List<AWS::EC2::VPC::Id>",
  "Description" : "VpcId Ids"
}
于 2017-07-10T14:52:00.593 回答