Improve operational performance by enabling Amazon DevOps Guru across multiple AWS Regions, accounts, and OUs with the AWS CDK
Created by Dr. Rahul Sharad Gaikwad (AWS)
Summary
This pattern demonstrates the steps to enable the Amazon DevOps Guru service across multiple Amazon Web Services (AWS) Regions, accounts, and organizational units (OUs) by using the AWS Cloud Development Kit (AWS CDK) in TypeScript. You can use AWS CDK stacks to deploy AWS CloudFormation StackSets from the administrator (primary) AWS account to enable Amazon DevOps Guru across multiple accounts, instead of logging into each account and enabling DevOps Guru individually for each account.
Amazon DevOps Guru provides artificial intelligence operations (AIOps) features to help you improve the availability of your applications and resolve operational issues faster. DevOps Guru reduces your manual effort by applying machine learning (ML) powered recommendations, without requiring any ML expertise. DevOps Guru analyzes your resources and operational data. If it detects any anomalies, it provides metrics, events, and recommendations to help you address the issue.
This pattern describes three deployment options for enabling Amazon DevOps Guru:
For all stack resources across multiple accounts and Regions
For all stack resources across OUs
For specific stack resources across multiple accounts and Regions
Prerequisites and limitations
Prerequisites
An active AWS account.
AWS Command Line Interface (AWS CLI), installed and configured. (See Installing, updating, and uninstalling the AWS CLI in the AWS CLI documentation.)
AWS CDK Toolkit, installed and configured. (See AWS CDK Toolkit in the AWS CDK documentation.)
Node Package Manager (npm), installed and configured for the AWS CDK in TypeScript. (See Downloading and installing Node.js and npm
in the npm documentation.) Python3 installed and configured, for running a Python script to inject traffic into the sample serverless application. (See Python Setup and Usage
in the Python documentation.) Pip, installed and configured to install the Python requests library. (See the pip installation instructions
on the PyPl website.)
Product versions
AWS CDK Toolkit version 1.107.0 or later
npm version 7.9.0 or later
Node.js version 15.3.0 or later
Architecture
Technologies
The architecture for this pattern includes the following services:
AWS CDK stacks
The pattern uses the following AWS CDK stacks:
CdkStackSetAdminRole
– Creates an AWS Identity and Access management (IAM) administrator role to establish a trust relationship between the administrator and target accounts.CdkStackSetExecRole
– Creates an IAM role to trust the administrator account.CdkDevopsGuruStackMultiAccReg
– Enables DevOps Guru across multiple AWS Regions and accounts for all stacks, and sets up Amazon Simple Notification Service (Amazon SNS) notifications.CdkDevopsGuruStackMultiAccRegSpecStacks
– Enables DevOps Guru across multiple AWS Regions and accounts for specific stacks, and sets up Amazon SNS notifications.CdkDevopsguruStackOrgUnit
– Enables DevOps Guru across OUs, and sets up Amazon SNS notifications.CdkInfrastructureStack
– Deploys sample serverless application components such as API Gateway, Lambda, and DynamoDB in the administrator account to demonstrate fault injection and insights generation.
Sample application architecture
The following diagram illustrates the architecture of a sample serverless application that has been deployed across multiple accounts and Regions. The pattern uses the administrator account to deploy all the AWS CDK stacks. It also uses the administrator account as one of the target accounts for setting up DevOps Guru.
When DevOps Guru is enabled, it first baselines each resource’s behavior and then ingests operational data from CloudWatch vended metrics.
If it detects an anomaly, it correlates it with the events from CloudTrail, and generates an insight.
The insight provides a correlated sequence of events along with prescribed recommendations to enable the operator to identify the culprit resource.
Amazon SNS sends notification messages to the operator.

Automation and scale
The GitHub repository
Tools
AWS services
AWS CDK – AWS Cloud Development Kit (AWS CDK) helps you define your cloud infrastructure as code in one of five supported programming languages: TypeScript, JavaScript, Python, Java, and C#.
AWS CLI – AWS Command Line Interface (AWS CLI) is a unified tool that provides a consistent command-line interface for interacting with AWS services and resources.
Code
The source code for this pattern is available on GitHub, in the Amazon DevOps Guru CDK Samples
Important
Some of the stories in this pattern include AWS CDK and AWS CLI command examples that are formatted for Unix, Linux, and macOS. For Windows, replace the backslash (\) continuation character at the end of each line with a caret (^).
Epics
Task | Description | Skills required |
---|---|---|
Configure AWS named profiles. | Set up your AWS named profiles as follows to deploy stacks in a multi-account environment. For the administrator account:
For the target account:
For more information, see Using named profiles in the AWS CLI documentation. | DevOps engineer |
Verify AWS profile configurations. | (Optional) You can verify your AWS profile configurations in the | DevOps engineer |
Verify the AWS CDK version. | Verify the version of the AWS CDK Toolkit by running the following command:
This pattern requires version 1.107.0 or later. If you have an earlier version of the AWS CDK, follow the instructions in the AWS CDK documentation to update it. | DevOps engineer |
Clone the project code. | Clone the GitHub repository for this pattern by using the command:
| DevOps engineer |
Install package dependencies and compile the TypeScript files. | Install the package dependencies and compile the TypeScript files by running the following commands:
These commands install all the packages from the sample repository. ImportantIf you get any errors about missing packages, use one of the following commands:
—or—
You can find the list of package names and versions in the | DevOps engineer |
Task | Description | Skills required |
---|---|---|
Configure an email address for Amazon SNS notifications. | Follow these steps to provide an email address for Amazon SNS notifications:
| DevOps engineer |
Build the project code. | Build the project code and synthesize the stacks by running the command:
You should see output similar to the following:
For more information and steps, see Your first AWS CDK app in the AWS CDK documentation. | DevOps engineer |
List the AWS CDK stacks. | Run the following command to list all AWS CDK stacks:
The command displays the following list:
| DevOps engineer |
Task | Description | Skills required |
---|---|---|
Deploy the AWS CDK stacks for creating IAM roles. | This pattern uses AWS CloudFormation StackSets to perform stack operations across multiple accounts. If you are creating your first stack set, you must create the following IAM roles to get the required permissions set up in your AWS accounts:
NoteThe roles must have these exact names.
For more information, see Grant self-managed permissions in the AWS CloudFormation documentation. | DevOps engineer |
Deploy the AWS CDK stack for enabling DevOps Guru across multiple accounts. | The AWS CDK
Currently Amazon DevOps Guru is available in the AWS Regions listed in the DevOps Guru FAQ | DevOps engineer |
Task | Description | Skills required |
---|---|---|
Extract OU IDs. | On the AWS Organizations | DevOps engineer |
Enable service-managed permissions for OUs. | If you're using AWS Organizations for account management, you must grant service-managed permissions to enable DevOps Guru. Instead of creating the IAM roles manually, use organization-based trusted access and service-linked roles (SLRs). | DevOps engineer |
Deploy the AWS CDK stack for enabling DevOps Guru across OUs. | The AWS CDK
| DevOps engineer |
Task | Description | Skills required |
---|---|---|
Deploy the AWS CDK stacks for creating IAM roles. | If you haven't already created the required IAM roles shown in the first option, do that first:
For more information, see Grant self-managed permissions in the AWS CloudFormation documentation. | DevOps engineer |
Delete existing stacks. | If you already used the first option to enable DevOps Guru for all stack resources, you can delete the old stack by using the following command:
Or, you can change the | DevOps engineer |
Update the AWS CDK stack with a stack list. |
| Data engineer |
Deploy the AWS CDK stack for enabling DevOps Guru for specific stack resources across multiple accounts. | The AWS CDK
NoteIf you previously deployed this stack for option 1, change the | DevOps engineer |
Task | Description | Skills required |
---|---|---|
Deploy the sample serverless infrastructure stack. | The AWS CDK
| DevOps engineer |
Insert sample records in DynamoDB. | Run the following command to populate the DynamoDB table with sample records. Provide the correct path for the
The command displays the following output:
| DevOps engineer |
Verify inserted records in DynamoDB. | To verify that the DynamoDB table includes the sample records from the
| DevOps engineer |
Wait for resources to complete baselining. | This serverless stack has a few resources. We recommend that you wait for 2 hours before you carry out the next steps. If you deployed this stack in a production environment, it might take up to 24 hours to complete baselining, depending on the number of resources you selected to monitor in DevOps Guru. | DevOps engineer |
Task | Description | Skills required |
---|---|---|
Update the AWS CDK infrastructure stack. | To try out DevOps Guru insights, you can make some configuration changes to reproduce a typical operational issue.
| DevOps engineer |
Inject HTTP requests on the API. | Inject ingress traffic in the form of HTTP requests on the
| DevOps engineer |
Review DevOps Guru insights. | Under standard conditions, the DevOps Guru dashboard displays zero in the ongoing insights counter. If it detects an anomaly, it raises an alert in the form of an insight. In the navigation pane, choose Insights to see the details of the anomaly, including an overview, aggregated metrics, relevant events, and recommendations. For more information about reviewing insights, see the Gaining operational insights with AIOps using Amazon DevOps Guru | DevOps engineer |
Task | Description | Skills required |
---|---|---|
Clean up and delete resources. | After you walk through this pattern, you should remove the resources you created to avoid incurring any further charges. Run these commands:
| DevOps engineer |