How do i validate an aws cloudformation template using the aws-cli?



  • AWS cloudformation has an option to validate your template.

    {
        "Resources" : {
            "HelloBucket" : {
                "Type" : "AWS::S3::Bucket"
            }
        } 
    }
    

    To validate this template run this command:

    $ aws cloudformation validate-template --template-body file://s3sample.json
    {
        "Parameters": []
    }
    

    Believe it or not that means it's fine.

    You would know pretty quickly if there was an error, for example remove one double quote from the template file and running it again, and it tells you line 4, column 24 in where the syntax error is.

    $ aws cloudformation validate-template --template-body file://s3sample.json
    
    An error occurred (ValidationError) when calling the ValidateTemplate operation: Template format error: JSON not well-formed. (line 4, column 23)
    

    Usually you will be working on editors with code validating enabled like Atom or vim with plugins installed for checking JSON code.


Log in to reply
 

© Lightnetics 2024