gpt4 book ai didi

python - Boto3云信息错误: Template format error: unsupported structure

转载 作者:行者123 更新时间:2023-11-28 18:58:37 27 4
gpt4 key购买 nike

我无法将参数加载到 python boto3 Cloudformation 客户端中。

下面是我的参数文件:

[
{"ParameterKey": "pVpcId", "ParameterValue": "vpc-XXXXXX"},
{"ParameterKey": "pContact", "ParameterValue": "XDXDXX"},
{"ParameterKey": "pCC", "ParameterValue": "XXXXX" },
{"ParameterKey": "pFormat", "ParameterValue": "True"}
]

我通过以下方式将其加载到程序中:

    with open(parameter_file, 'r') as infile:
parameters=ast.literal_eval(infile.read())
client = boto3.client('cloudformation',aws_access_key_id=access_key,aws_secret_access_key=secret_key,aws_session_token=session_token,region_name=region)

response = client.create_stack(
StackName=stack_name,
TemplateURL=stack_url,
Parameters=parameters
)

当我使用 Cloudformation 建立 boto3 客户端并调用它时,出现如下错误。该调用无需参数即可工作,因此肯定与参数文件有关。

    Traceback (most recent call last):
File "cf_create_stack", line 85, in <module>
Parameters=parameters
File "/usr/lib/python2.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/lib/python2.7/site-packages/botocore/client.py", line 661, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the CreateStack operation: Template format error: unsupported structure.

最佳答案

因此 TemplateBody 参数需要 CloudFormation 模板文件的内容/str,而不仅仅是文件名。

以下内容应该可以令人满意地工作。

cf_template = open('batch-job-cft.yml').read()
cf_client.create_stack(StackName='Batch Job', TemplateBody=cf_template)

# OR

# Optimal usage would be as below
with open('batch-job-cft.yml', 'r') as cf_file:
cft_template = cf_file.read()
cf_client.create_stack(StackName='Batch Job', TemplateBody=cft_template)

关于python - Boto3云信息错误: Template format error: unsupported structure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55341010/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com