有没有办法在同一区域克隆 Cloudformation 堆栈?

Pra*_*adK 6 amazon-web-services aws-cloudformation

我想在同一区域克隆一个 cloudformation 堆栈。现在使用 Cloudformation 控制台可以实现这一点吗?

我有一个云信息模板,它接受大量参数。很多时候我想创建一个相同的堆栈,只是使用不同的堆栈名称。有没有使用 AWS 控制台快速执行此操作的方法?

我正在考虑类似于 EC2 中“启动更多这样的”选项的内容。

小智 5

我使用以下 shell 脚本

#!/bin/sh -x

# debug
if [ -z "$1" ] ; then
  STACK=jirithhu-monitorStack-1ALS8UFQP3SRV
else
  STACK="$1"
fi


set -e

# parameter 1: stack ID  : (example: hhu-monitorStack-1ALS8UFQP3SRV )

aws cloudformation  describe-stacks --stack-name $STACK | jq .Stacks[0].Parameters > /tmp/xx.$$.pars
aws cloudformation get-template  --stack-name $STACK | jq -rc .TemplateBody > /tmp/xx.$$.body

NEWNAME=`echo "COPY-$STACK"`

aws cloudformation create-stack --stack-name $NEWNAME \
    --template-body file:///tmp/xx.$$.body\
    --parameters "`cat /tmp/xx.$$.pars`" \
    --capabilities '[ "CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND" ]'

rm /tmp/xx.$$*
Run Code Online (Sandbox Code Playgroud)


Sud*_*ran -2

您可以创建一个输入文件并快速启动一个新堆栈。

例如: 命令:

aws cloudformation create-stack --stackname startmyinstance  
    --template-body file://startmyinstance.json 
    --parameters file://startmyinstance-parameters.json
Run Code Online (Sandbox Code Playgroud)

参数文件:

[
  {
    "ParameterKey": "KeyPairName",
    "ParameterValue": "MyKey"
  }, 
  {
    "ParameterKey": "InstanceType",
    "ParameterValue": "m1.micro"
  }
]
Run Code Online (Sandbox Code Playgroud)

参考: https: //aws.amazon.com/blogs/devops/passing-parameters-to-cloudformation-stacks-with-the-aws-cli-and-powershell/