

# PutConfigRule
<a name="API_PutConfigRule"></a>

Adds or updates an Amazon Config rule to evaluate if your Amazon resources comply with your desired configurations. For information on how many Amazon Config rules you can have per account, see [https://docs.amazonaws.cn/config/latest/developerguide/configlimits.html](https://docs.amazonaws.cn/config/latest/developerguide/configlimits.html) in the * Amazon Config Developer Guide*.

There are two types of rules: * Amazon Config Managed Rules* and * Amazon Config Custom Rules*. You can use `PutConfigRule` to create both Amazon Config Managed Rules and Amazon Config Custom Rules.

 Amazon Config Managed Rules are predefined, customizable rules created by Amazon Config. For a list of managed rules, see [List of Amazon Config Managed Rules](https://docs.amazonaws.cn/config/latest/developerguide/managed-rules-by-aws-config.html). If you are adding an Amazon Config managed rule, you must specify the rule's identifier for the `SourceIdentifier` key.

 Amazon Config Custom Rules are rules that you create from scratch. There are two ways to create Amazon Config custom rules: with Lambda functions ([Amazon Lambda Developer Guide](https://docs.amazonaws.cn/config/latest/developerguide/gettingstarted-concepts.html#gettingstarted-concepts-function)) and with Guard ([Guard GitHub Repository](https://github.com/aws-cloudformation/cloudformation-guard)), a policy-as-code language. Amazon Config custom rules created with Amazon Lambda are called * Amazon Config Custom Lambda Rules* and Amazon Config custom rules created with Guard are called * Amazon Config Custom Policy Rules*.

If you are adding a new Amazon Config Custom Lambda rule, you first need to create an Amazon Lambda function that the rule invokes to evaluate your resources. When you use `PutConfigRule` to add a Custom Lambda rule to Amazon Config, you must specify the Amazon Resource Name (ARN) that Amazon Lambda assigns to the function. You specify the ARN in the `SourceIdentifier` key. This key is part of the `Source` object, which is part of the `ConfigRule` object. 

For any new Amazon Config rule that you add, specify the `ConfigRuleName` in the `ConfigRule` object. Do not specify the `ConfigRuleArn` or the `ConfigRuleId`. These values are generated by Amazon Config for new rules.

If you are updating a rule that you added previously, you can specify the rule by `ConfigRuleName`, `ConfigRuleId`, or `ConfigRuleArn` in the `ConfigRule` data type that you use in this request.

For more information about developing and using Amazon Config rules, see [Evaluating Resources with Amazon Config Rules](https://docs.amazonaws.cn/config/latest/developerguide/evaluate-config.html) in the * Amazon Config Developer Guide*.

**Note**  
 **Tags are added at creation and cannot be updated with this operation**   
 `PutConfigRule` is an idempotent API. Subsequent requests won’t create a duplicate resource if one was already created. If a following request has different `tags` values, Amazon Config will ignore these differences and treat it as an idempotent request of the previous. In this case, `tags` will not be updated, even if they are different.  
Use [TagResource](https://docs.amazonaws.cn/config/latest/APIReference/API_TagResource.html) and [UntagResource](https://docs.amazonaws.cn/config/latest/APIReference/API_UntagResource.html) to update tags after creation.

## Request Syntax
<a name="API_PutConfigRule_RequestSyntax"></a>

```
{
   "ConfigRule": { 
      "ConfigRuleArn": "string",
      "ConfigRuleId": "string",
      "ConfigRuleName": "string",
      "ConfigRuleState": "string",
      "CreatedBy": "string",
      "Description": "string",
      "EvaluationModes": [ 
         { 
            "Mode": "string"
         }
      ],
      "InputParameters": "string",
      "MaximumExecutionFrequency": "string",
      "Scope": { 
         "ComplianceResourceId": "string",
         "ComplianceResourceTypes": [ "string" ],
         "TagKey": "string",
         "TagValue": "string"
      },
      "Source": { 
         "CustomPolicyDetails": { 
            "EnableDebugLogDelivery": boolean,
            "PolicyRuntime": "string",
            "PolicyText": "string"
         },
         "Owner": "string",
         "SourceDetails": [ 
            { 
               "EventSource": "string",
               "MaximumExecutionFrequency": "string",
               "MessageType": "string"
            }
         ],
         "SourceIdentifier": "string"
      }
   },
   "Tags": [ 
      { 
         "Key": "string",
         "Value": "string"
      }
   ]
}
```

## Request Parameters
<a name="API_PutConfigRule_RequestParameters"></a>

For information about the parameters that are common to all actions, see [Common Parameters](CommonParameters.md).

The request accepts the following data in JSON format.

 ** [ConfigRule](#API_PutConfigRule_RequestSyntax) **   <a name="config-PutConfigRule-request-ConfigRule"></a>
The rule that you want to add to your account.  
Type: [ConfigRule](API_ConfigRule.md) object  
Required: Yes

 ** [Tags](#API_PutConfigRule_RequestSyntax) **   <a name="config-PutConfigRule-request-Tags"></a>
An array of tag object.  
Type: Array of [Tag](API_Tag.md) objects  
Array Members: Minimum number of 0 items. Maximum number of 50 items.  
Required: No

## Response Elements
<a name="API_PutConfigRule_ResponseElements"></a>

If the action is successful, the service sends back an HTTP 200 response with an empty HTTP body.

## Errors
<a name="API_PutConfigRule_Errors"></a>

For information about the errors that are common to all actions, see [Common Error Types](CommonErrors.md).

 ** InsufficientPermissionsException **   
Indicates one of the following errors:  
+ For [PutConfigRule](https://docs.amazonaws.cn/config/latest/APIReference/API_PutConfigRule.html), the rule cannot be created because the IAM role assigned to Amazon Config lacks permissions to perform the config:Put\$1 action.
+ For [PutConfigRule](https://docs.amazonaws.cn/config/latest/APIReference/API_PutConfigRule.html), the Amazon Lambda function cannot be invoked. Check the function ARN, and check the function's permissions.
+ For [PutOrganizationConfigRule](https://docs.amazonaws.cn/config/latest/APIReference/API_PutOrganizationConfigRule.html), organization Amazon Config rule cannot be created because you do not have permissions to call IAM `GetRole` action or create a service-linked role.
+ For [PutConformancePack](https://docs.amazonaws.cn/config/latest/APIReference/API_PutConformancePack.html) and [PutOrganizationConformancePack](https://docs.amazonaws.cn/config/latest/APIReference/API_PutOrganizationConformancePack.html), a conformance pack cannot be created because you do not have the following permissions: 
  + You do not have permission to call IAM `GetRole` action or create a service-linked role.
  + You do not have permission to read Amazon S3 bucket or call SSM:GetDocument.
+ For [PutServiceLinkedConfigurationRecorder](https://docs.amazonaws.cn/config/latest/APIReference/API_PutServiceLinkedConfigurationRecorder.html), a service-linked configuration recorder cannot be created because you do not have the following permissions: IAM `CreateServiceLinkedRole`.
HTTP Status Code: 400

 ** InvalidParameterValueException **   
One or more of the specified parameters are not valid. Verify that your parameters are valid and try again.  
HTTP Status Code: 400

 ** MaxNumberOfConfigRulesExceededException **   
Failed to add the Amazon Config rule because the account already contains the maximum number of 1000 rules. Consider deleting any deactivated rules before you add new rules.  
HTTP Status Code: 400

 ** NoAvailableConfigurationRecorderException **   
There are no customer managed configuration recorders available to record your resources. Use the [PutConfigurationRecorder](https://docs.amazonaws.cn/config/latest/APIReference/API_PutConfigurationRecorder.html) operation to create the customer managed configuration recorder.  
HTTP Status Code: 400

 ** ResourceInUseException **   
You see this exception in the following cases:   
+ For DeleteConfigRule, Amazon Config is deleting this rule. Try your request again later.
+ For DeleteConfigRule, the rule is deleting your evaluation results. Try your request again later.
+ For DeleteConfigRule, a remediation action is associated with the rule and Amazon Config cannot delete this rule. Delete the remediation action associated with the rule before deleting the rule and try your request again later.
+ For PutConfigOrganizationRule, organization Amazon Config rule deletion is in progress. Try your request again later.
+ For DeleteOrganizationConfigRule, organization Amazon Config rule creation is in progress. Try your request again later.
+ For PutConformancePack and PutOrganizationConformancePack, a conformance pack creation, update, and deletion is in progress. Try your request again later.
+ For DeleteConformancePack, a conformance pack creation, update, and deletion is in progress. Try your request again later.
HTTP Status Code: 400

## See Also
<a name="API_PutConfigRule_SeeAlso"></a>

For more information about using this API in one of the language-specific Amazon SDKs, see the following:
+  [Amazon Command Line Interface V2](https://docs.amazonaws.cn/goto/cli2/config-2014-11-12/PutConfigRule) 
+  [Amazon SDK for .NET V4](https://docs.amazonaws.cn/goto/DotNetSDKV4/config-2014-11-12/PutConfigRule) 
+  [Amazon SDK for C\$1\$1](https://docs.amazonaws.cn/goto/SdkForCpp/config-2014-11-12/PutConfigRule) 
+  [Amazon SDK for Go v2](https://docs.amazonaws.cn/goto/SdkForGoV2/config-2014-11-12/PutConfigRule) 
+  [Amazon SDK for Java V2](https://docs.amazonaws.cn/goto/SdkForJavaV2/config-2014-11-12/PutConfigRule) 
+  [Amazon SDK for JavaScript V3](https://docs.amazonaws.cn/goto/SdkForJavaScriptV3/config-2014-11-12/PutConfigRule) 
+  [Amazon SDK for Kotlin](https://docs.amazonaws.cn/goto/SdkForKotlin/config-2014-11-12/PutConfigRule) 
+  [Amazon SDK for PHP V3](https://docs.amazonaws.cn/goto/SdkForPHPV3/config-2014-11-12/PutConfigRule) 
+  [Amazon SDK for Python](https://docs.amazonaws.cn/goto/boto3/config-2014-11-12/PutConfigRule) 
+  [Amazon SDK for Ruby V3](https://docs.amazonaws.cn/goto/SdkForRubyV3/config-2014-11-12/PutConfigRule) 