Creating a rule for tags using AWS Guard Rules

0

We have a specific AMI we use for creating ec2 instances that have a specific application installed.

I'd like to create a rule within AWS Guard Rules that makes sure people are creating the required tags and providing the required values within the keys.

I've tried to use regex and other AWS specific rulesets such as what's listed below but receive the same error, also shown below. Does anyone have any basic rules I can use as a template and I can work from there?

Error

error: error one or more of the specified parameters are invalid.aws guard rule

Code I Searched From GitHub Search

AWS::EC2::VPC Tags == /."Key":"Environment"./ << the mandatory Tag: Environment is not specified AWS::EC2::VPC Tags == /."Key":"ApplicationName"./ << the mandatory Tag: ApplicationName is not specified

Code I Searched From regex

policies: name: ec2-tag-compliance amazon.aws.ec2_tag: region: us-east-1 resource: ec2 filters:

rule check_applepie_year {
let applepie_regex = /ApplePie-(?!0000)\d{4}/
Resources.*[ Type == "AWS::EC2::Instance" ] {
    Properties.Tags[?Key == "Name"].Value == %appplepie_regex
}

}

<<You must follow the format - ApplePie-urlprefix-4digityear-city Example: ApplePie-crusty2023-NY

rule check_tags { Metadata.Tags.Application << /(?i)ApplePie/ Metadata.Tags.Environment << /(?i)Acceptance/ Metadata.Tags.Platform << /(?i)RedHat/ }

<< You must have the following tags - Application, Environment, Platform The key values must contain - Apollo, Production, Ubuntu

let required_tags = ["Project Code", "Web_URL"] rule check_tags { Resources.[ Type == "AWS::EC2::Instance" ] { Properties.Tags[].Key IN %required_tags Properties.Tags[*].Value NOT_EMPTY } }

<< You must have the following tags - Project Code, Web_URL The key values must contain - Requesters project code, URL to be used by clients

actions:
  - stop
已提問 9 個月前檢視次數 413 次
1 個回答
0

You can seen the built in required-tags rule for Config? https://docs.aws.amazon.com/config/latest/developerguide/required-tags.html

This checks for a tag but not the value. Does this work or do you need to check value?

profile picture
專家
已回答 9 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南