Skip to content

AWS Account

Usage

Create new Account

To create a new Account, use the Account Construct provided.

import { Construct } from 'constructs';
import {
  Organization,
  OrganizationUnit,
  Account,
} from '@jttc/aws-organizations';

export class OrganizationStack extends Construct {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    const organization = new Organization(this, 'Organization');

    const workloadOrganizationUnit = new OrganizationUnit(
      this,
      'WorkloadsOrganizationUnit',
      {
        organizationUnitName: 'workloads',
        parent: organization,
      }
    );

    new Account(this, 'ProdAccount', {
      accountName: 'prodc-account',
      email: 'prod@example.com'
      parent: workloadOrganizationUnit,
    });
  }
}

Existing account

The construct provides a method to import a oaccount from existing one

import { Construct } from 'constructs';
import { Account } from '@jttc/aws-organizations';

export class OrganizationStack extends Construct {
  constructor(scope: Construct, id: string) {
    super(scope, id);

    Account.fromAccountAttributes(this, 'ProdAccount', {
      accountId: '123456789012',
      organizationUnitId: 'ou-8470ddj',
    });
  }
}