- Newest
- Most votes
- Most comments
The issue with your CloudFormation template is in the Query property of the ResourceQuery. Instead of providing a JSON string, you need to provide a JSON object directly. Here's the corrected version of your template:
{ "Resources": { "rgrname": { "Type": "AWS::ResourceGroups::Group", "Properties": { "Description": "Resource group containing all ec2 instances with name tag prod", "Name": "rgr_prod_servers", "ResourceQuery": { "Type": "TAG_FILTERS_1_0", "Query": { "ResourceTypeFilters": ["AWS::EC2::Instance"], "TagFilters": [ { "Key": "Name", "Values": ["prod"] } ] } } } } } }
The key difference is that the Query property is now a JSON object instead of a JSON-encoded string. This matches the expected format for the CloudFormation template.
The reason you're seeing a different format when using the AWS CLI is that the CLI often requires JSON to be passed as a string, which is why it appears encoded. However, in CloudFormation templates, you should provide the actual JSON structure directly.
This corrected template should resolve the "Model validation failed" error you were encountering. It creates a resource group that includes all EC2 instances tagged with the key "Name" and value "prod".
Sources
AWS::ResourceGroups::Group - AWS CloudFormation
Build a tag-based query and create a group - AWS Resource Groups
