python-3.x - python中的AWS cloudform包

标签 python-3.x amazon-web-services aws-cloudformation

我只是想问是否有什么方法可以用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中吗?谢谢!任何帮助将不胜感激。

最佳答案

有两种方法:

  1. 使用适用于 CloudFormation 的 Python 面向目标编程库,并让该库处理您的嵌套堆栈和打包。这是一个例子:https://cottonformation.readthedocs.io/en/latest/01-cottonformation-by-example/index.html#nested-stack-template
  2. 使用 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/

相关文章:

aws-cloudformation - 无服务器部署问题

python - 名称错误 : Factory name not defined - Kivy

Python:使用检查创建函数签名

python - 删除列表列表中存在的重复整数列表,而不考虑整数列表的排序

reactjs - AWS 全栈应用程序部署教程构建失败

amazon-web-services - 我是否充分利用了我的 EMR 集群?

python-3.x - 未指定 base_name 参数,并且无法从 View 集自动确定名称,因为它没有 .queryset 属性

linux - AWS ECS 上的 Docker 容器始终显示 STOPPED

aws-cloudformation - Aurora PostgreSQL 的 CloudFormation 模板

amazon-web-services - 使用自动扩展创建 EC2 时,是否可以在 Cloud Formation Template 中为 EC2 添加 CNAME?