我只是想问是否有什么方法可以用python制作aws cloudformation包?这是 awscli 中的代码:
aws cloudformation package \
--region us-east-1 \
--profile $Profile \
--template-file templates/$TEMPLATE.yml \
--s3-bucket $ARTIFACT_BUCKET \
--output-template-file $d-$TEMPLATE-$Profile.packaged.yml
我想要这个在Python中吗?谢谢!任何帮助将不胜感激。
最佳答案
有两种方法:
- 使用适用于 CloudFormation 的 Python 面向目标编程库,并让该库处理您的嵌套堆栈和打包。这是一个例子:https://cottonformation.readthedocs.io/en/latest/01-cottonformation-by-example/index.html#nested-stack-template
- 使用 subprocess 标准库从 Python 调用 shell 命令:
import os
import subprocess
subprocess.run(
[
"aws", "cloudformation", "package",
"--region", "us-east-1"
"--profile", os.environ["Profile"], # use os.environ to get the env var value
"--template-file", f'templates/{os.environ["TEMPLATE"]}.yml',
"--s3-bucket", os.environ["ARTIFACT_BUCKET"],
"--output-template-file", f'{os.environ["d"]}-{os.environ["TEMPLATE"]}-{os.environ["Profile"]}.packaged.yml',
],
check=True, # if failed, stop the script immediately, prevent the sub sequence command to run
)
关于python-3.x - python中的AWS cloudform包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62335943/