自动化Cloudformation模板部署 [英] Automate the Cloudformation template Deployment

查看:113
本文介绍了自动化Cloudformation模板部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Cloudformation模板来配置AWS中的资源。

I am currently using Cloudformation templates to provision resources in AWS.

当前,如果我需要创建VPC和安全组,首先,我将从模板创建VPC,然后再次为安全组启动另一个模板,在该模板中手动输入VPC ID。

Currently, if I need to create a VPC and Security groups, First I will create VPC from a template and again I will launch another template for security group where I manually input the VPC ID.

现在,我需要在Cloudformation中自动化此手动过程。我怎样才能做到这一点?我可以使用AWS Developer工具或其他自动化工具吗?

Now, I need to automate this manual process in Cloudformation. How can I do this? Can I use AWS Developer tools or other automation tools?

推荐答案

简短答案



您需要遵循一种输出惯例您创建的任何AWS资源的ARN /名称,因此如果以后需要它们,则可以通过在新模板中进行导入来通过简单的引用轻松地实现。

Short answer

You need to follow a practice of outputting the ARNs/Names of any AWS resources that you create so if you need them later on, you can easily do that by a simple reference by doing an import in the new template.

如上文Nimo的回答所述,为此,您将需要使用导出函数输出部分中包含您期望可以重复使用的任何资源的所有模板。然后,以后您可以轻松地使用 Fn :: ImportValue 使用先前创建的资源,而无需知道资源的实际物理ID。这称为跨堆栈引用。

As explained in the answer above by Nimo, for this, you will need to use the Export function in the Outputs section for all templates for any resources that you expect might be reused. And then later you can easily use Fn::ImportValue to use a previously created resource, without knowing the actual physical ID of the resource. This is called cross-stack referencing.

似乎您需要持续集成和持续部署(CICD ),以便您将代码更改直接/自动部署到AWS。您将为此设置管道,以下是最简单但并非唯一的方法:

It seems like you need Continuous Integration and Continuous Deployment (CICD) for your infrastructure so your code changes will be deployed directly/automatically to AWS. You will have to set up pipelines for this and following is the simplest but not the only way:


  1. 使用Github / AWS codecommit等用于存储您的CloudFormation代码
    并将其触发器设置为分支您的 master 分支,因此其中的任何
    更改都会触发管道,并且它将自动部署这些
    更改。

  1. Use Github/AWS codecommit etc. for storing your CloudFormation code and set its trigger to a branch e.g. your master branch so any changes in it will trigger the pipeline and it will deploy those changes automatically.

为此目的使用AWS的本机服务AWS CodePipeline。这是
,您可以在其中定义具有多个阶段的完整管道,而每个阶段可能有许多动作,每个阶段都会创建一个堆栈。所有堆栈都可以使用先前创建的堆栈的输出,并且一些东西也可以传递到参数中。为此,您必须使用 AWS :: CodePipeline :: Pipeline 作为资源来创建新堆栈。

Use AWS's native service AWS CodePipeline for this purpose. This is where you can define a complete pipeline with various stages while each stage may have many actions and each creating a stack. All stacks may use outputs from the previously created stacks and some stuff can be passed into the parameters as well. For this, you will have to create a new stack with AWS::CodePipeline::Pipeline as a resource.

在没有导出功能的情况下也将输出用于
那些您认为需要的资源。例如,如果您有
,则
可能需要负载平衡器的DNS端点。

Use outputs also for the resources without the export function for those resources which you think you will need. Like for example, you might want the load balancer's DNS endpoint, if you have one.

此处是参考管道堆栈,它使用s3作为存储代码的源。

Here is a Reference Pipeline Stack which uses s3 as the source for the stored code.

这篇关于自动化Cloudformation模板部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆