Create a CFN stack from template using get template

0 votes

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.

Jan 24, 2023 in AWS by Tejashwini
• 3,820 points
260 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Creating a linux virtual machine from disk in azure using python

You specifically ask... Can anyone explain the answer ...READ MORE

answered Aug 30, 2018 in AWS by Priyaj
• 58,090 points
842 views
0 votes
1 answer

How to create new stack using create-change-set in AWS Cloudformation

The type of change set operation. To ...READ MORE

answered Sep 18, 2018 in AWS by Priyaj
• 58,090 points
3,652 views
+1 vote
1 answer

How to issue a parsing json from case class using jackson?

Do you use jackson-module-scala or any other Scala-aware configuration ...READ MORE

answered Sep 26, 2018 in AWS by Priyaj
• 58,090 points
2,785 views
0 votes
1 answer

Import my AWS credentials using python script

Using AWS Cli  Configure your IAM user then ...READ MORE

answered Nov 16, 2018 in AWS by Jino
• 5,810 points
2,593 views
0 votes
1 answer

AWS S3 uploading hidden files by default

versioning is enabled in your bucket. docs.aws.amazon.com/AmazonS3/latest/user-guide/….... the ...READ MORE

answered Oct 4, 2018 in AWS by Priyaj
• 58,090 points
5,455 views
–1 vote
1 answer

How to decrypt the encrypted S3 file using aws-encryption-cli --decrypt

Use command : aws s3 presign s3://mybucket/abc_count.png you get ...READ MORE

answered Oct 22, 2018 in AWS by Priyaj
• 58,090 points
4,868 views
0 votes
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP