Import an Existing IAM Group in AWS CDK


Borislav Hadzhiev

Wed Apr 28 20211 min read

Importing an existing IAM Group in AWS CDK #

In order to import an external IAM Group in an AWS CDK stack, we have to use the fromGroupArn static method on the Group class.

import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; export class CdkStarterStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { super(scope, id, props); // 👇 import existing Group const importedGroup = iam.Group.fromGroupArn( this, 'existing-group-id', `arn:aws:iam::${cdk.Stack.of(this).account}:group/YOUR_GROUP_NAME`, ); console.log('imported group name 👉', importedGroup.groupName); console.log('imported group arn 👉', importedGroup.groupArn); } }

In the code snippet we used the fromGroupArn static method on the Group class to import an external group. The method takes 3 parameters:

  1. scope - the scope of the construct
  2. id - an identifier for the construct (must be unique within the scope)
  3. groupArn - the ARN of the group we want to import

Further Reading #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee