@@ -281,6 +281,63 @@ export class ManagedRule extends RuleNew {
281281  } 
282282} 
283283
284+ /** 
285+  * The source of the event, such as an AWS service, 
286+  * that triggers AWS Config to evaluate your AWS resources. 
287+  */ 
288+ enum  EventSource  { 
289+ 
290+   /* from aws.config */ 
291+   AWS_CONFIG  =  'aws.config' , 
292+ 
293+ } 
294+ 
295+ /** 
296+  * The type of notification that triggers AWS Config to run an evaluation for a rule. 
297+  */ 
298+ enum  MessageType  { 
299+ 
300+   /** 
301+    * Triggers an evaluation when AWS Config delivers a configuration item as a result of a resource change. 
302+    */ 
303+   CONFIGURATION_ITEM_CHANGE_NOTIFICATION  =  'ConfigurationItemChangeNotification' , 
304+ 
305+   /** 
306+    * Triggers an evaluation when AWS Config delivers an oversized configuration item. 
307+    */ 
308+   OVERSIZED_CONFIGURATION_ITEM_CHANGE_NOTIFICATION  =  'OversizedConfigurationItemChangeNotification' , 
309+ 
310+   /** 
311+    * Triggers a periodic evaluation at the frequency specified for MaximumExecutionFrequency. 
312+    */ 
313+   SCHEDULED_NOTIFICATION  =  'ScheduledNotification' , 
314+ 
315+   /** 
316+    * Triggers a periodic evaluation when AWS Config delivers a configuration snapshot. 
317+    */ 
318+   CONFIGURATION_SNAPSHOT_DELIVERY_COMPLETED  =  'ConfigurationSnapshotDeliveryCompleted' , 
319+ } 
320+ 
321+ /** 
322+  * Construction properties for a CustomRule. 
323+  */ 
324+ interface  SourceDetail  { 
325+   /** 
326+    * The source of the event, such as an AWS service, 
327+    * that triggers AWS Config to evaluate your AWS resources. 
328+    * 
329+    */ 
330+   readonly  eventSource : EventSource ; 
331+   /** 
332+    * The frequency at which you want AWS Config to run evaluations for a custom rule with a periodic trigger. 
333+    */ 
334+   readonly  maximumExecutionFrequency ?: MaximumExecutionFrequency ; 
335+   /** 
336+    * The type of notification that triggers AWS Config to run an evaluation for a rule. 
337+    */ 
338+   readonly  messageType : MessageType ; 
339+ } 
340+ 
284341/** 
285342 * Construction properties for a CustomRule. 
286343 */ 
@@ -331,25 +388,24 @@ export class CustomRule extends RuleNew {
331388      throw  new  Error ( 'At least one of `configurationChanges` or `periodic` must be set to true.' ) ; 
332389    } 
333390
334-     const  sourceDetails : any [ ]  =  [ ] ; 
391+     const  sourceDetails : SourceDetail [ ]  =  [ ] ; 
335392    this . ruleScope  =  props . ruleScope ; 
336- 
337393    if  ( props . configurationChanges )  { 
338394      sourceDetails . push ( { 
339-         eventSource : 'aws.config' , 
340-         messageType : 'ConfigurationItemChangeNotification' , 
395+         eventSource : EventSource . AWS_CONFIG , 
396+         messageType : MessageType . CONFIGURATION_ITEM_CHANGE_NOTIFICATION , 
341397      } ) ; 
342398      sourceDetails . push ( { 
343-         eventSource : 'aws.config' , 
344-         messageType : 'OversizedConfigurationItemChangeNotification' , 
399+         eventSource : EventSource . AWS_CONFIG , 
400+         messageType : MessageType . OVERSIZED_CONFIGURATION_ITEM_CHANGE_NOTIFICATION , 
345401      } ) ; 
346402    } 
347403
348404    if  ( props . periodic )  { 
349405      sourceDetails . push ( { 
350-         eventSource : 'aws.config' , 
406+         eventSource : EventSource . AWS_CONFIG , 
351407        maximumExecutionFrequency : props . maximumExecutionFrequency , 
352-         messageType : 'ScheduledNotification' , 
408+         messageType : MessageType . SCHEDULED_NOTIFICATION , 
353409      } ) ; 
354410    } 
355411
@@ -391,6 +447,88 @@ export class CustomRule extends RuleNew {
391447  } 
392448} 
393449
450+ /** 
451+  * Construction properties for a CustomPolicy. 
452+  */ 
453+ export  interface  CustomPolicyProps  extends  RuleProps  { 
454+   /** 
455+    * The policy definition containing the logic for your AWS Config Custom Policy rule. 
456+    */ 
457+   readonly  policyText : string ; 
458+ 
459+   /** 
460+    * The boolean expression for enabling debug logging for your AWS Config Custom Policy rule. 
461+    * 
462+    * @default  false 
463+    */ 
464+   readonly  enableDebugLog ?: boolean ; 
465+ } 
466+ 
467+ /** 
468+  * A new custom policy. 
469+  * 
470+  * @resource  AWS::Config::ConfigRule 
471+  */ 
472+ export  class  CustomPolicy  extends  RuleNew  { 
473+   /** @attribute  */ 
474+   public  readonly  configRuleName : string ; 
475+ 
476+   /** @attribute  */ 
477+   public  readonly  configRuleArn : string ; 
478+ 
479+   /** @attribute  */ 
480+   public  readonly  configRuleId : string ; 
481+ 
482+   /** @attribute  */ 
483+   public  readonly  configRuleComplianceType : string ; 
484+ 
485+   constructor ( scope : Construct ,  id : string ,  props : CustomPolicyProps )  { 
486+     super ( scope ,  id ,  { 
487+       physicalName : props . configRuleName , 
488+     } ) ; 
489+ 
490+     if  ( ! props . policyText  ||  [ ...props . policyText ] . length  ===  0 )  { 
491+       throw  new  Error ( 'Policy Text cannot be empty.' ) ; 
492+     } 
493+     if  (  [ ...props . policyText ] . length  >  10000  )  { 
494+       throw  new  Error ( 'Policy Text is limited to 10,000 characters or less.' ) ; 
495+     } 
496+ 
497+     const  sourceDetails : SourceDetail [ ]  =  [ ] ; 
498+     this . ruleScope  =  props . ruleScope ; 
499+ 
500+     sourceDetails . push ( { 
501+       eventSource : EventSource . AWS_CONFIG , 
502+       messageType : MessageType . CONFIGURATION_ITEM_CHANGE_NOTIFICATION , 
503+     } ) ; 
504+     sourceDetails . push ( { 
505+       eventSource : EventSource . AWS_CONFIG , 
506+       messageType : MessageType . OVERSIZED_CONFIGURATION_ITEM_CHANGE_NOTIFICATION , 
507+     } ) ; 
508+     const  rule  =  new  CfnConfigRule ( this ,  'Resource' ,  { 
509+       configRuleName : this . physicalName , 
510+       description : props . description , 
511+       inputParameters : props . inputParameters , 
512+       scope : Lazy . any ( {  produce : ( )  =>  renderScope ( this . ruleScope )  } ) ,  // scope can use values such as stack id (see CloudFormationStackDriftDetectionCheck) 
513+       source : { 
514+         owner : 'CUSTOM_POLICY' , 
515+         sourceDetails, 
516+         customPolicyDetails : { 
517+           enableDebugLogDelivery : props . enableDebugLog , 
518+           policyRuntime : 'guard-2.x.x' , 
519+           policyText : props . policyText , 
520+         } , 
521+       } , 
522+     } ) ; 
523+ 
524+     this . configRuleName  =  rule . ref ; 
525+     this . configRuleArn  =  rule . attrArn ; 
526+     this . configRuleId  =  rule . attrConfigRuleId ; 
527+     this . configRuleComplianceType  =  rule . attrComplianceType ; 
528+     this . isCustomWithChanges  =  true ; 
529+   } 
530+ } 
531+ 
394532/** 
395533 * Managed rules that are supported by AWS Config. 
396534 * @see  https://docs.aws.amazon.com/config/latest/developerguide/managed-rules-by-aws-config.html 
0 commit comments