我对AWS和Python都是新手
在AWS CLI中,以下命令工作正常:
aws cloudformation package --template-file sam.yaml --output-template-file output-sam.yaml --s3-bucket <<bucket_Name>>
目标是创建自动运行上述命令的python脚本。我试着用谷歌搜索,但没有一个解决方案对我有效
下面是我尝试过但无法将工件上传到S3存储桶的解决方案
test.py文件:
import subprocess
command= ["aws","cloudformation","package","--template-file","sam.yaml","--output-template-file","output-sam.yaml","--s3-bucket","<<bucket_name>>"]
print(subprocess.check_output(command, stderr=subprocess.STDOUT))
使用操作系统库可以很容易地完成。代码中给出了最简单的方法
然而,子流程可以用于一些复杂的任务。 您还可以查看boto3库中的此类任务。Boto是用于Python的AWS SDK
您可以检查这个
aws-cli
命令is implemented,因为它已经全部在Python中了。基本上aws cloudformation package
会将模板上载到S3,因此您可以使用注释中提到的boto3
执行相同的操作相关问题 更多 >
编程相关推荐