템플릿 확인
aws cloudformation validate-template
명령을 사용하여 템플릿 파일의 구문 오류를 점검할 수 있습니다.
참고
aws cloudformation validate-template
명령은 템플릿의 구문만 점검하도록 설계되어 있습니다. 리소스에 대해 지정한 속성 값이 해당 리소스에 유효한지 확인하지는 않습니다. 생성된 스택에 존재하게 될 리소스 수를 결정하지도 않습니다.
운영상 유효성을 점검하려면 스택을 만들어 보아야 합니다. AWS CloudFormation 스택에는 샌드박스나 테스트 영역이 없기 때문에 테스트 중 만든 리소스는 본인이 담당해야 합니다.
확인 중에 AWS CloudFormation에서는 먼저 템플릿이 유효한 JSON인지를 확인합니다. 유효한 JSON이 아니면 CloudFormation은 템플릿이 유효한 YAML인지를 확인합니다. 두 확인이 모두 실패한 경우 CloudFormation에서는 템플릿 확인 오류를 반환합니다. --template-body
파라미터를 로컬로 또는 --template-url
파라미터를 사용하여 원격으로 템플릿을 확인할 수 있습니다.
유효한 템플릿
다음 예에서는 --template-url
파라미터를 전달하여 원격 위치에서 템플릿을 확인합니다.
aws cloudformation validate-template --template-url https://s3.amazonaws.com/cloudformation-templates-us-east-1/S3_Bucket.template
다음은 이전 명령의 출력입니다.
{
"Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket.
You will be billed for the AWS resources used if you create a stack from this template.",
"Parameters": [],
"Capabilities": []
}
예상 결과는 오류 메시지가 표시되지 않고 나열된 모든 파라미터에 대한 정보가 표시되는 것입니다.
유효성 검사 오류
이 섹션에서는 aws cloudformation validate-template
명령을 실행할 때 유효성 검사 오류를 생성합니다.
다음 예에서는 --template-body
파라미터를 전달하여 로컬에서 템플릿을 확인합니다.
aws cloudformation validate-template --template-body file:///home/local/test/sampletemplate.json
다음은 이전 명령의 출력입니다.
{ "ResponseMetadata": { "RequestId": "4ae33ec0-1988-11e3-818b-e15a6df955cd" }, "Errors": [ { "Message": "Template format error: JSON not well-formed. (line 11, column 8)", "Code": "ValidationError", "Type": "Sender" } ], "Capabilities": [], "Parameters": [] } A client error (ValidationError) occurred: Template format error: JSON not well-formed. (line 11, column 8)
예상 결과는 오류 메시지가 표시되고 나열된 오류에 대한 정보가 표시되는 것입니다.