Enabling cross-account functionality in CloudWatch without AWS console

0

I would like to automate the process of Enabling cross-account functionality in CloudWatch for each new account so that there is no need to go through this link tutorial on each new account.

I have an account dedicated to monitoring that should have CloudWatch access by default in every new and existing account in the organisation.

Ideally, it would be possible to set something like this up via CDK, but any alternative would be welcome.

質問済み 2年前2910ビュー
1回答
1
承認された回答

If you have a look at what the console is doing, it just deploys a single CloudFormation template into the account, creating one IAM role: CloudWatch-CrossAccountSharingRole. Repeating the same with CDK or CloudFormation is how you can automate. For AWS Organizations integration, have a look at CloudFormation StackSets which can auto-deploy the IAM role to new accounts as they are onboarded.

Here is the YAML for a typical CloudFormation stack that creates the needed role (same as what you'll see deployed in the AWS Console):

---
Parameters:
  MonitoringAccountIds:
    Description: Allows one or more monitoring accounts to view your data. Enter AWS account ids, 12 numeric digits in comma-separated list
    Type: CommaDelimitedList
    Default: 012345678901

Conditions:
  CWCrossAccountSupported: {"Fn::Equals": [{"Ref": "AWS::Partition"}, "aws"]}

Resources:
  CWCrossAccountSharingRole:
    Condition: "CWCrossAccountSupported"
    Type: AWS::IAM::Role
    Properties:
      RoleName: CloudWatch-CrossAccountSharingRole
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              AWS: !Split
                - ','
                - !Sub
                  - 'arn:${AWS::Partition}:iam::${inner}:root'
                  - inner: !Join
                      - ':root,arn:${AWS::Partition}:iam::'
                      - Ref: MonitoringAccountIds
            Action:
              - sts:AssumeRole
      Path: "/"
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess
        - arn:aws:iam::aws:policy/CloudWatchAutomaticDashboardsAccess

AWS
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ