I am trying to create a CFN stack from a template, using get_template() and passing the stack id but when trying to create the stack, I get the error:
Response
{
"errorMessage": "Parameter validation failed:\nInvalid type for parameter TemplateBody, value: {'TemplateBody': OrderedDict([('Resources', OrderedDict([('BastionHostInstanceSecurityGroupE75D4274', OrderedDict([('Type', 'AWS::EC2::SecurityGroup'), ('Properties', OrderedDict([('GroupDescription', 'SharedInfraPipelineStack/Dev/BastionInfraStack/BastionHost/Resource/InstanceSecurityGroup'), ........ 'ResponseMetadata': {'RequestId': '117d66c7-7bb4-4c92-9c41-0680c943dbb7', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '117d66c7-7bb4-4c92-9c41-0680c943dbb7', 'content-type': 'text/xml', 'content-length': '8055', 'date': 'Mon, 23 Jan 2023 21:16:00 GMT'}, 'RetryAttempts': 0}}, type: <class 'dict'>, valid types: <class 'str'>",
"errorType": "ParamValidationError",
"requestId": "f879686f-2cbf-4b75-aa7e-b940535f0a7d",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 22, in lambda_handler\n create_cfn_stack(stack_name, stack_id)\n",
" File \"/var/task/lambda_function.py\", line 43, in create_cfn_stack\n cfn.create_stack(\n",
" File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n return self._make_api_call(operation_name, kwargs)\n",
" File \"/var/runtime/botocore/client.py\", line 691, in _make_api_call\n request_dict = self._convert_to_request_dict(\n",
" File \"/var/runtime/botocore/client.py\", line 739, in _convert_to_request_dict\n request_dict = self._serializer.serialize_to_request(\n",
" File \"/var/runtime/botocore/validate.py\", line 360, in serialize_to_request\n raise ParamValidationError(report=report.generate_report())\n"
]
}
This is how I'm getting the template and passing it to the create_stack function:
def create_cfn_stack(stack_name, stack_id):
try:
template = cfn.get_template(StackName=stack_id)
cfn.create_stack(
StackName=stack_name,
TemplateBody=template,
Capabilities=['CAPABILITY_IAM']
)
logger.info("Success :: create_cfn_stack %s", stack_name)
except ClientError as error:
logger.error(error)
return None
return "created:OK"
So, what am I missing?
Thanks.