AWS Cloud Operations Blog
Implementing a cross-account and cross-Region AWS Config status dashboard
AWS Config helps central IT administrators monitor the compliance of multiple AWS accounts and multiple regions in large enterprises. AWS Config utilizes a configuration recorder to detect changes in your resource configurations and capture these as configuration items. A separate configuration recorder exists for every region in each AWS account.
However, AWS Config recorders can occasionally stop for various reasons, such as invalid delivery channel permissions, inadvertent error, etc. This Cross-Account Cross-Region AWS Config status dashboard Solution lets you monitor the status of AWS Config recorders across multiple accounts and regions via Amazon CloudWatch custom metrics on a single management account. Then, the administrators can setup alarms on these custom metrics to be notified when the status of these AWS Config recorder changes.
This application is deployed in a management account, and the AWS Lambda functions access each member account and region in an AWS Organization or member accounts list in order to check the AWS Config recorder’s status. It then publishes the status of the AWS Config recorder for each account and region to Amazon CloudWatch as custom metrics. At this point, the operators can define metric alarms on these custom metrics and trigger alarm actions to notify team members via Amazon Simple Notification Service (Amazon SNS).
Architecture
Figure 1: Asolution architecture for the cross-account. cross-region Config dashboard
Prerequisites
To utilize our ‘AwsConfigStatusChecker’ application, you need the following tools:
• AWS CLI – Install the AWS CLI
• SAM CLI – Install the SAM CLI. The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications.
• Python 3.8 – Install Python
• At this time, you must launch this solution in the US East (N. Virginia) Region. However, once deployed, the solution will monitor AWS Config recorders for multiple regions and multiple AWS Accounts from the AWS CloudFormation StackSet’s target.
Download the solution
How to build and deploy this application
The application has 2 directories:
• awsconfigstatuscheck-app – A SAM Application with AWS Lambda functions and AWS CloudFormation Template (template.yaml) to deploy the resources by using SAM CLI. This application is deployed in the AWS Organization management account.
• StacksetCFTemplate – This directory contains an AWS CloudFormation StackSet templatefile that defines the IAM Role and IAM Policy deployed on the member accounts. This IAM Policy and IAM Role is necessary on the member accounts for the application to assumeRole and gather AWS Config service status.
- Build the application with the
sam build
command.
Sample Output:
- This second command will package and deploy your application to AWS via a series of prompts:
Provide the following as input when you run the command:
-
- Stack Name: Provide any name here for e.g. ‘awsconfigstatuscheck-app’
- AWS Region: us-east-1 – This is the supported region for this solution.
- Parameters:
- CheckFrequencyMins – This parameter defines how often the lambda function executes to check for the status of AWS Config s The allowed Values are “rate(5 minutes)”, “rate(15 minutes)”, “rate(30 minutes)”, “rate(60 minutes)”, and “rate(90 minutes)”.
- CheckAllAccountsinOrgCondition – If set to true, then MemberAccountIds Parameter is ignored, and the application checks the status of AWS Config in all accounts/regions across the AWS Organization. If set to false, then proceed to setting the MemberAccountIds parameter. Allowed Values are “true” or “false”.
- MemberAccountIds – If the parameter CheckAllAccountsinOrgCondition is set to false, then enter a comma separated list of AWS account IDs where you want the application to check for the status of AWS Config. Leave this parameter to its default value if you set CheckAllAccountsinOrgCondition to true. [e.g., 12345634344,434345555333,455454545324]
- Confirm changes before deploy: If set to yes, then any change sets will be shown to you for manual review before execution. If set to no, then the AWS SAM CLI will automatically deploy application changes.
- Allow SAM CLI IAM role creation: To deploy this application’s AWS CloudFormation stack, which creates or modifies IAM roles, the CAPABILITY_IAM value for capabilities must be provided. If the permission isn’t provided through this prompt, then in order to deploy this example you must explicitly pass –capabilities CAPABILITY_IAM to the sam deploy command.
- Save arguments to samconfig.toml: If set to yes, then your choices will be saved to a configuration file inside the project. This is so that in the future you can just re-run sam deploy without parameters in order to deploy changes to your application.
Sample Output:
- Create an AWS CloudFormation StackSet by using AWS CLI. Provide the AWS Management account ID where this StackSet will be deployed.
Sample Output:
StacksetCFTemplate$ aws cloudformation create-stack-set \
> --description "role/policies for aws config checker" \
> --stack-set-name aws-config-checker-stackset \
> --template-body file://stacksettemplate.yml \
> --permission-model SERVICE_MANAGED \
> --capabilities CAPABILITY_NAMED_IAM \
> --parameters ParameterKey=AdministratorAccountId,ParameterValue=xxxxxxxxxx \
> --auto-deployment Enabled=true,RetainStacksOnAccountRemoval=false
{
"StackSetId": "aws-config-checker-stackset:273c07d1-c7ab-4e6c-b388-0f6e2263c400"
}
- Create an AWS CloudFormation Stack Instances by using AWS CLI. Provide the OrganizationalUnitIds of the member accounts to which the Stack Instances are deployed.
Sample Output:
Troubleshooting the Lambda function
In order to simplify troubleshooting, SAM CLI has a command called sam logs
. sam logs
lets you fetch logs generated by your deployed Lambda function from the command line. In addition to printing the logs on the terminal, this command has several useful features to help you quickly find the bug.
View the status of AWS Config Recorders across target accounts as Amazon CloudWatch Custom Metrics.
After a few minutes, log in to Amazon CloudWatch Console to view custom metrics of AWS Config recorders by region and account.
Figure 2: Sample Amazon CloudWatch Console
As shown below, you can create a dashboard in Amazon CloudWatch in order to view the AWSConfig Status custom metrics in a single view. Create alarms in CloudWatch in order to watch for a decrease in the number of running AWS Config recorders. Then, define an action in order to send a notification to an Amazon SNS Topic and/or create an OpsItem or incident in AWS Systems Manager.
Figure 3: AWS CloudWatch Dashboard Sample
Cleanup
- To delete the AwsConfigStatusCheck application that you created, use the SAM CLI.
- Delete the Stack Instances from AWS CloudFormation StackSet using AWS CLI.
- Wait for Step 2 to finish. Then, delete the AWS CloudFormation StackSet using AWS CLI.
Conclusion
This post provided a solution that can be easily deployed on a management account in order to monitor the status of AWS Config recorders on multiple accounts and regions. The solution publishes custom metrics to Amazon CloudWatch. AWS administrator and operators can setup CloudWatch alarms to be notified when the status of an AWS Config recorder’s status changes for any reason .