Skip to main content

AWS CDK Construct Library to manage specific AWS Organization resources

Project description

cdk-library-aws-organization

This CDK library is a WIP and not ready for production use.

Key challenges with Organizations

  • Accounts aren't like AWS resources and the removal process isn't a simple delete. Therefore the constructs contained in this library do not have the goal to delete accounts.
  • CloudFormation doesn't support Organizations directly so the constructs in this library use CloudFormation custom resources that utilize Python and Boto3

Testing the custom provider code with SAM CLI

Pre-reqs

  • You will either want a previously created test account or allow the tests to create a new account

Testing

  • Create a test project that utilizes this library (you can use a development version by utilizing yarn link, but note you might need to set a static dependency for CDK versions or constructs in the local app or you'll get errors about mismatched object types)
  • Create a test stack
  • Synthesize the test stack with cdk synth --no-staging > template.yml
  • Get the handler function names from the template
  • Run sam local start-lambda -t template.yml
  • Run the handler_tests python files with pytest like follows:
TEST_ACCOUNT_NAME='<name>' TEST_ACCOUNT_EMAIL='<email>' TEST_ACCOUNT_ORIGINAL_OU='<original ou id>' ACCOUNT_LAMBDA_FUNCTION_NAME='<name you noted earlier>' OU_LAMBDA_FUNCTION_NAME='<name you noted earlier>' pytest ./handler_tests/<test file name>.py -rA --capture=sys
  • Using the name, email, and original OU env variables here allows the test suite to re-use a single test account. Given deleting accounts is not simple you likely dont want to randomly create a new account every time you run tests.
  • The test.py also looks up the root org id to run tests so you'll need to have AWS creds set up to accomodate that behavior.
  • You can run the provided tests against the real lambda function by getting the deployed function name from AWS and setting the RUN_LOCALLY env variable
TEST_ACCOUNT_NAME='<name>' TEST_ACCOUNT_EMAIL='<email>' TEST_ACCOUNT_ORIGINAL_OU='<original ou id>' RUN_LOCALLY='false' ACCOUNT_LAMBDA_FUNCTION_NAME='<name you noted earlier>' OU_LAMBDA_FUNCTION_NAME='<name from AWS>' pytest ./handler_tests/<test file name>.py -rA --capture=sys

Why can't I move an OU?

Moving OUs isn't supported by Organizations and would cause significant issues with keeping track of OUs in the CDK. Imagine a scenario like below:

  • You have an ou, OUAdmin, and it has 2 children, OUChild1 and Account1, that are also managed by the CDK stack.

  • You change the parent of OUAdmin to OUFoo. The CDK would need to take the following actions:

    • Create a new OU under OUFoo with the name OUAdmin

    • Move all of the original OUAdmin OU's children to the new OUAdmin

    • Delete the old OUAdmin

    • Update all physical resource IDs

      • It would succeed at moving accounts because physical IDs should not change. Accounting moving between OUs is supported by Organizations
      • It would fail at moving any child OUs because they would also be recreated. Resulting in a change to physical resource ID. Because the custom resource can only managed the resource it's currently acting on, OUAdmin, any children OUs would be "lost" in this process and ugly to try and manage.

The best way to move OUs would be to add additional OUs to your org then move any accounts as needed then proceed to delete the OUs, like so:

  • Add new OU resources
  • Deploy the stack
  • Change account parents
  • Deploy the stack
  • Remove old OU resources
  • Deploy the stack

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file renovosolutions.aws-cdk-aws-organization-0.4.40.tar.gz.

File metadata

  • Download URL: renovosolutions.aws-cdk-aws-organization-0.4.40.tar.gz
  • Upload date:
  • Size: 57.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for renovosolutions.aws-cdk-aws-organization-0.4.40.tar.gz
Algorithm Hash digest
SHA256 87fd6d72963ce74c4259aea164e22240ba85127286ee9d6e1854a1ecb79e36dc
MD5 e5cfea3dbaa38f110ac2d1f357c43782
BLAKE2b-256 3e6a11b0b18827268b78ce62841d0d9e7226c237408ec528cec851aeb89a79cd

See more details on using hashes here.

File details

Details for the file renovosolutions.aws_cdk_aws_organization-0.4.40-py3-none-any.whl.

File metadata

  • Download URL: renovosolutions.aws_cdk_aws_organization-0.4.40-py3-none-any.whl
  • Upload date:
  • Size: 55.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for renovosolutions.aws_cdk_aws_organization-0.4.40-py3-none-any.whl
Algorithm Hash digest
SHA256 470eba22f865cdf53d4b994e6dc3687e9cb106dc57c0acf16cc192438c929aa6
MD5 f24b6e18c80ba51a6c9a6f717d02e324
BLAKE2b-256 aef3f7a771520b8e6344f8182b8ad2907e7863c42a047ddba3e5009ea5e48131

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page