简体   繁体   English

如何指示 AWS CloudFormation 模板在特定区域创建资源?

[英]How can I instruct an AWS CloudFormation template to create resources in a specific region?

I am new to CloudFormation templates.我是 CloudFormation 模板的新手。 I have basic template in yaml that creates an EC2 Instance.我在 yaml 中有创建 EC2 实例的基本模板。 Every time I create a stack and use this template, the EC2 Instance is ALWAYS created on US East N. Virginia region.每次我创建堆栈并使用此模板时,EC2 实例总是在美国东部弗吉尼亚北部地区创建。 I am trying to change this so that the EC2 Instance resides in US-WEST-2 region.我正在尝试更改此设置,以便 EC2 实例位于 US-WEST-2 区域。 After some research, it appears that this is something that is not specified within the template.经过一些研究,这似乎是模板中未指定的内容。 Instead, I need to change the region to us-west-2 in AWS console and then create a new stack.相反,我需要在 AWS 控制台中将区域更改为 us-west-2,然后创建一个新堆栈。 Is my understanding correct?我的理解正确吗?

Unfortunately, you can't specify the region in a cloudformation template.不幸的是,您无法在 cloudformation 模板中指定区域。

You should either pass region as a command line argument您应该将区域作为命令行参数传递

aws --region eu-west-1 cloudformation create-stack --stack-name ...

or, specify the default region in aws cli config file ~/.aws/config或者,在 aws cli 配置文件~/.aws/config指定默认区域

[default]
region=eu-west-1

What am I missing here?我在这里缺少什么? I am sure we can specify region where the stack is created in CFN template using parameters and we do have active templates which creates our stack in respective region based on the parameter value.我确信我们可以使用参数指定在 CFN 模板中创建堆栈的区域,并且我们确实有活动模板,可以根据参数值在相应的区域中创建我们的堆栈。 The AWS::Region pseudo parameter is a value that AWS CloudFormation resolves as the region where the stack is created. AWS::Region 伪参数是 AWS CloudFormation 将其解析为堆栈创建区域的值。 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/gettingstarted.templatebasics.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/gettingstarted.templatebasics.html

Here is a sub-section of sample template这是示例模板的一个子部分

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "InstanceType": {
      "Description": "Instance Type",
      "Type": "String",
      "Default": "t2.xlarge"
    },
    "SubnetUSEAST1": {
      "Description": "Subnet on which Ec2 instance needs to be created",
      "Type": "String",
      "Default": "subnet-xxxxxxxx"
    },
    "SubnetUSWEST2": {
      "Description": "Subnet on which Ec2 instance needs to be created",
      "Type": "String",
      "Default": "subnet-yyyyyyyy"
    }
  },
  "Conditions": {
    "useast1": {
      "Fn::Equals": [
        {
          "Ref": "AWS::Region"
        },
        "us-east-1"
      ]
    },
    "uswest2": {
      "Fn::Equals": [
        {
          "Ref": "AWS::Region"
        },
        "us-west-2"
      ]
    }
  },
  "Resources": {
    "EC2Instance": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "InstanceType": {
          "Ref": "InstanceType"
        },
        "NetworkInterfaces": [
          {
            "SubnetId": {
              "Fn::If": [
                "useast1",
                {
                  "Ref": "SubnetUSEAST1"
                },
                {
                  "Ref": "SubnetUSWEST2"
                }
              ]
            },
            "AssociatePublicIpAddress": "false",
            "DeviceIndex": "0"
          }
        ]
      }
    }
  }
}

如果您能够将模板拆分为多个部分,则可以通过一些编排和StackSets一次部署到不同的区域。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为 AWS CloudFormation 堆栈和资源实施特定于区域的配置 - How to implement region specific configuration for AWS CloudFormation stack and resources 如何为特定 CloudFormation 堆栈创建“aws.cloudformation”CloudWatch 事件类型? - How can I create an "aws.cloudformation" CloudWatch event type for a specific CloudFormation stack? 如何将 AWS 资源转换为 cloudformation 堆栈或模板? - How to convert AWS resources to a cloudformation stack or template? 在不同区域创建CloudFormation资源 - Create CloudFormation resources in different region 如何从AWS CloudFormation模板为特定资源类型创建堆栈 - How to create stack for specific resource types from aws cloudformation template 如何自定义AWS Codestar / Cloudformation模板以创建特定的代码构建项目? - How to customize AWS Codestar / Cloudformation template to create specific codebuild project? 如何从 cloudformation 模板在不同区域创建/部署 lambda function? - How to create/deploy a lambda function in different region from cloudformation template? 圆形 ci cloudformation 模板 aws 区域错误 - circle ci cloudformation template aws region errror 我可以使用 AWS Cloudformation 模板在 AWS Aurora(Postgres 风格)中创建和修改表吗? - Can I use an AWS Cloudformation template to create and modify tables in AWS Aurora (Postgres flavour)? 如何在Cloudformation模板参数中创建IAM角色下拉列表 - How can I create IAM Role Dropdown in Cloudformation Template Parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM