Search code examples
aws-cloudformationaws-cli

cloudformation update-stack with --cli-input-json and TemplateBody


I am trying to use aws cloudformation update-stack with --cli-input-json but I also want the "TemplateBody":"[...]" value to point to a file like I can do with --template-body file://template.yml.

Is that possible?

Thanks!


Solution

  • No it's not supported.

    You'll get this error message:

    An error occurred (ValidationError) when calling the UpdateStack operation: Template format error: unsupported structure.

    Firstly, your template body has to be JSON in the cli-input-json so let's say you have template.json.

    When you provide --template-body via the command line, the CLI realises that you're providing a file to be read, reads it and then supplies the JSON contents to the API.

    However, when you use cli-input-json, the CLI parses it literally1 & identifies file://template.json as invalid JSON that isn't in the CloudFormation template format.


    1 You can see this if you run your command using --debug (this is CreateStack but same concept applies):

    2023-09-30 11:29:17,259 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=CreateStack) with params: {'url_path': '/', 'query_string': '', 'method': 'POST', 'headers': {'Content-Type': 'xxx', 'User-Agent': 'xxx'}, 'body': {'Action': 'CreateStack', 'Version': '2010-05-15', 'StackName': 'xxx', 'TemplateBody': 'file://template.json'}, 'url': 'xxx', 'context': {'client_region': 'xxx', 'client_config': <botocore.config.Config object at 0x10fa0a650>, 'has_streaming_input': False, 'auth_type': None}}