Skip to main content

@cdklabs/cdk-enterprise-iac

Project description

CDK Enterprise IaC

Utilities for using CDK within enterprise constraints

Install

Typescript

npm install @cdklabs/cdk-enterprise-iac

Python

pip install cdklabs.cdk-enterprise-iac

Usage

Example for AddPermissionBoundary in Typescript project.

import * as cdk from 'aws-cdk-lib';
import { MyStack } from '../lib/my-project-stack';
import { Aspects } from 'aws-cdk-lib';
import { AddPermissionBoundary } from '@cdklabs/cdk-enterprise-iac';

const app = new cdk.App();
new MyStack(app, 'MyStack');

Aspects.of(app).add(
  new AddPermissionBoundary({
    permissionsBoundaryPolicyName: 'MyPermissionBoundaryName',
    instanceProfilePrefix: 'MY_PREFIX_', // optional, Defaults to ''
    policyPrefix: 'MY_POLICY_PREFIX_', // optional, Defaults to ''
    rolePrefix: 'MY_ROLE_PREFIX_', // optional, Defaults to ''
  })
);

Example for AddPermissionBoundary in Python project.

import aws_cdk as cdk
from cdklabs.cdk_enterprise_iac import AddPermissionBoundary
from test_py.test_py_stack import TestPyStack


app = cdk.App()
TestPyStack(app, "TestPyStack")

cdk.Aspects.of(app).add(AddPermissionBoundary(
    permissions_boundary_policy_name="MyPermissionBoundaryName",
    instance_profile_prefix="MY_PREFIX_",  # optional, Defaults to ""
    policy_prefix="MY_POLICY_PREFIX_",  # optional, Defaults to ""
    role_prefix="MY_ROLE_PREFIX_"  # optional, Defaults to ""
))

app.synth()

Details in API.md

Generated API.md


Generated API.md below:

Expand to view API docs

API Reference

Constructs

EcsIsoServiceAutoscaler

Creates a EcsIsoServiceAutoscaler construct.

This construct allows you to scale an ECS service in an ISO region where classic ECS Autoscaling may not be available.

Initializers

import { EcsIsoServiceAutoscaler } from '@cdklabs/cdk-enterprise-iac'

new EcsIsoServiceAutoscaler(scope: Construct, id: string, props: EcsIsoServiceAutoscalerProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props EcsIsoServiceAutoscalerProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired

Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { EcsIsoServiceAutoscaler } from '@cdklabs/cdk-enterprise-iac'

EcsIsoServiceAutoscaler.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.
ecsScalingManagerFunction aws-cdk-lib.aws_lambda.Function No description.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


ecsScalingManagerFunctionRequired
public readonly ecsScalingManagerFunction: Function;
  • Type: aws-cdk-lib.aws_lambda.Function

PopulateWithConfig

Populate a provided VPC with subnets based on a provided configuration.

Example

const mySubnetConfig: SubnetConfig[] = [
   {
     groupName: 'app',
     cidrRange: '172.31.0.0/27',
     availabilityZone: 'a',
     subnetType: subnetType.PUBLIC,
   },
   {
     groupName: 'app',
     cidrRange: '172.31.0.32/27',
     availabilityZone: 'b',
     subnetType: subnetType.PUBLIC,
   },
   {
     groupName: 'db',
     cidrRange: '172.31.0.64/27',
     availabilityZone: 'a',
     subnetType: subnetType.PRIVATE_WITH_EGRESS,
   },
   {
     groupName: 'db',
     cidrRange: '172.31.0.96/27',
     availabilityZone: 'b',
     subnetType: subnetType.PRIVATE_WITH_EGRESS,
   },
   {
     groupName: 'iso',
     cidrRange: '172.31.0.128/26',
     availabilityZone: 'a',
     subnetType: subnetType.PRIVATE_ISOLATED,
   },
   {
     groupName: 'iso',
     cidrRange: '172.31.0.196/26',
     availabilityZone: 'b',
     subnetType: subnetType.PRIVATE_ISOLATED,
   },
 ];
new PopulateWithConfig(this, "vpcPopulater", {
  vpcId: 'vpc-abcdefg1234567',
  privateRouteTableId: 'rt-abcdefg123456',
  localRouteTableId: 'rt-123456abcdefg',
  subnetConfig: mySubnetConfig,
})

Initializers

import { PopulateWithConfig } from '@cdklabs/cdk-enterprise-iac'

new PopulateWithConfig(scope: Construct, id: string, props: PopulateWithConfigProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props PopulateWithConfigProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired

Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { PopulateWithConfig } from '@cdklabs/cdk-enterprise-iac'

PopulateWithConfig.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


SplitVpcEvenly

Splits a VPC evenly between a provided number of AZs (3 if not defined), and attaches a provided route table to each, and labels.

Example

// with more specific properties
new SplitVpcEvenly(this, 'evenSplitVpc', {
  vpcId: 'vpc-abcdefg123456',
  vpcCidr: '172.16.0.0/16',
  routeTableId: 'rt-abcdefgh123456',
  cidrBits: '10',
  numberOfAzs: 4,
  subnetType: subnetType.PRIVATE_ISOLATED,
});

Initializers

import { SplitVpcEvenly } from '@cdklabs/cdk-enterprise-iac'

new SplitVpcEvenly(scope: Construct, id: string, props: SplitVpcEvenlyProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props SplitVpcEvenlyProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired

Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { SplitVpcEvenly } from '@cdklabs/cdk-enterprise-iac'

SplitVpcEvenly.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


Structs

AddCfnInitProxyProps

Properties for the proxy server to use with cfn helper commands.

Initializer

import { AddCfnInitProxyProps } from '@cdklabs/cdk-enterprise-iac'

const addCfnInitProxyProps: AddCfnInitProxyProps = { ... }

Properties

Name Type Description
proxyHost string host of your proxy.
proxyPort number proxy port.
proxyCredentials aws-cdk-lib.aws_secretsmanager.ISecret JSON secret containing user and password properties to use if your proxy requires credentials http://user:password@host:port could contain sensitive data, so using a Secret.
proxyType ProxyType Proxy Type.

proxyHostRequired
public readonly proxyHost: string;
  • Type: string

host of your proxy.


Example

example.com
proxyPortRequired
public readonly proxyPort: number;
  • Type: number

proxy port.


Example

8080
proxyCredentialsOptional
public readonly proxyCredentials: ISecret;
  • Type: aws-cdk-lib.aws_secretsmanager.ISecret

JSON secret containing user and password properties to use if your proxy requires credentials http://user:password@host:port could contain sensitive data, so using a Secret.

Note that while the user and password won't be visible in the cloudformation tempalte they will be in plain text inside your UserData


Example

const secret = new Secret(stack, 'TestSecret', {
 secretObjectValue: {
   user: SecretValue,
   password: SecretValue,
 },
});
proxyTypeOptional
public readonly proxyType: ProxyType;

Proxy Type.


Example

ProxyType.HTTPS

AddPermissionBoundaryProps

Properties to pass to the AddPermissionBoundary.

Initializer

import { AddPermissionBoundaryProps } from '@cdklabs/cdk-enterprise-iac'

const addPermissionBoundaryProps: AddPermissionBoundaryProps = { ... }

Properties

Name Type Description
permissionsBoundaryPolicyName string Name of Permissions Boundary Policy to add to all IAM roles.
instanceProfilePrefix string A prefix to prepend to the name of the IAM InstanceProfiles (Default: '').
policyPrefix string A prefix to prepend to the name of the IAM Policies and ManagedPolicies (Default: '').
rolePrefix string A prefix to prepend to the name of IAM Roles (Default: '').

permissionsBoundaryPolicyNameRequired
public readonly permissionsBoundaryPolicyName: string;
  • Type: string

Name of Permissions Boundary Policy to add to all IAM roles.


instanceProfilePrefixOptional
public readonly instanceProfilePrefix: string;
  • Type: string

A prefix to prepend to the name of the IAM InstanceProfiles (Default: '').


policyPrefixOptional
public readonly policyPrefix: string;
  • Type: string

A prefix to prepend to the name of the IAM Policies and ManagedPolicies (Default: '').


rolePrefixOptional
public readonly rolePrefix: string;
  • Type: string

A prefix to prepend to the name of IAM Roles (Default: '').


EcsIsoServiceAutoscalerProps

Initializer

import { EcsIsoServiceAutoscalerProps } from '@cdklabs/cdk-enterprise-iac'

const ecsIsoServiceAutoscalerProps: EcsIsoServiceAutoscalerProps = { ... }

Properties

Name Type Description
ecsCluster aws-cdk-lib.aws_ecs.Cluster The cluster the service you wish to scale resides in.
ecsService aws-cdk-lib.aws_ecs.IService The ECS service you wish to scale.
scaleAlarm aws-cdk-lib.aws_cloudwatch.Alarm The Cloudwatch Alarm that will cause scaling actions to be invoked, whether it's in or not in alarm will determine scale up and down actions.
maximumTaskCount number The maximum number of tasks that the service will scale out to.
minimumTaskCount number The minimum number of tasks the service will have.
role aws-cdk-lib.aws_iam.IRole Optional IAM role to attach to the created lambda to adjust the desired count on the ECS Service.
scaleInCooldown aws-cdk-lib.Duration How long will the application wait before performing another scale in action.
scaleInIncrement number The number of tasks that will scale in on scale in alarm status.
scaleOutCooldown aws-cdk-lib.Duration How long will a the application wait before performing another scale out action.
scaleOutIncrement number The number of tasks that will scale out on scale out alarm status.

ecsClusterRequired
public readonly ecsCluster: Cluster;
  • Type: aws-cdk-lib.aws_ecs.Cluster

The cluster the service you wish to scale resides in.


ecsServiceRequired
public readonly ecsService: IService;
  • Type: aws-cdk-lib.aws_ecs.IService

The ECS service you wish to scale.


scaleAlarmRequired
public readonly scaleAlarm: Alarm;
  • Type: aws-cdk-lib.aws_cloudwatch.Alarm

The Cloudwatch Alarm that will cause scaling actions to be invoked, whether it's in or not in alarm will determine scale up and down actions.


maximumTaskCountOptional
public readonly maximumTaskCount: number;
  • Type: number
  • Default: 10

The maximum number of tasks that the service will scale out to.

Note: This does not provide any protection from scaling out above the maximum allowed in your account, set this variable and manage account quotas appropriately.


minimumTaskCountOptional
public readonly minimumTaskCount: number;
  • Type: number
  • Default: 1

The minimum number of tasks the service will have.


roleOptional
public readonly role: IRole;
  • Type: aws-cdk-lib.aws_iam.IRole
  • Default: A role is created for you with least privilege IAM policy

Optional IAM role to attach to the created lambda to adjust the desired count on the ECS Service.

Ensure this role has appropriate privileges. Example IAM policy statements:

{
  "PolicyDocument": {
    "Statement": [
      {
        "Action": "cloudwatch:DescribeAlarms",
        "Effect": "Allow",
        "Resource": "arn:${Partition}:cloudwatch:${Region}:${Account}:alarm:${AlarmName}"
      },
      {
        "Action": [
          "ecs:DescribeServices",
          "ecs:UpdateService"
        ],
        "Condition": {
          "StringEquals": {
            "ecs:cluster": "arn:${Partition}:ecs:${Region}:${Account}:cluster/${ClusterName}"
          }
        },
        "Effect": "Allow",
        "Resource": "arn:${Partition}:ecs:${Region}:${Account}:service/${ClusterName}/${ServiceName}"
      }
    ],
    "Version": "2012-10-17"
  }
}

scaleInCooldownOptional
public readonly scaleInCooldown: Duration;
  • Type: aws-cdk-lib.Duration
  • Default: 60 seconds

How long will the application wait before performing another scale in action.


scaleInIncrementOptional
public readonly scaleInIncrement: number;
  • Type: number
  • Default: 1

The number of tasks that will scale in on scale in alarm status.


scaleOutCooldownOptional
public readonly scaleOutCooldown: Duration;
  • Type: aws-cdk-lib.Duration
  • Default: 60 seconds

How long will a the application wait before performing another scale out action.


scaleOutIncrementOptional
public readonly scaleOutIncrement: number;
  • Type: number
  • Default: 1

The number of tasks that will scale out on scale out alarm status.


PopulateWithConfigProps

Initializer

import { PopulateWithConfigProps } from '@cdklabs/cdk-enterprise-iac'

const populateWithConfigProps: PopulateWithConfigProps = { ... }

Properties

Name Type Description
localRouteTableId string Local route table ID, with routes only to local VPC.
privateRouteTableId string Route table ID for a provided route table with routes to enterprise network.
subnetConfig SubnetConfig[] List of Subnet configs to provision to provision.
vpcId string ID of the VPC provided that needs to be populated.

localRouteTableIdRequired
public readonly localRouteTableId: string;
  • Type: string

Local route table ID, with routes only to local VPC.


privateRouteTableIdRequired
public readonly privateRouteTableId: string;
  • Type: string

Route table ID for a provided route table with routes to enterprise network.

Both subnetType.PUBLIC and subnetType.PRIVATE_WITH_EGRESS will use this property


subnetConfigRequired
public readonly subnetConfig: SubnetConfig[];

List of Subnet configs to provision to provision.


vpcIdRequired
public readonly vpcId: string;
  • Type: string

ID of the VPC provided that needs to be populated.


RemoveTagsProps

Initializer

import { RemoveTagsProps } from '@cdklabs/cdk-enterprise-iac'

const removeTagsProps: RemoveTagsProps = { ... }

Properties

Name Type Description
cloudformationResource string Name of Cloudformation resource Type (e.g. 'AWS::Lambda::Function').
tagPropertyName string Name of the tag property to remove from the resource.

cloudformationResourceRequired
public readonly cloudformationResource: string;
  • Type: string

Name of Cloudformation resource Type (e.g. 'AWS::Lambda::Function').


tagPropertyNameOptional
public readonly tagPropertyName: string;
  • Type: string
  • Default: Tags

Name of the tag property to remove from the resource.


SetApiGatewayEndpointConfigurationProps

Initializer

import { SetApiGatewayEndpointConfigurationProps } from '@cdklabs/cdk-enterprise-iac'

const setApiGatewayEndpointConfigurationProps: SetApiGatewayEndpointConfigurationProps = { ... }

Properties

Name Type Description
endpointType aws-cdk-lib.aws_apigateway.EndpointType API Gateway endpoint type to override to.

endpointTypeOptional
public readonly endpointType: EndpointType;
  • Type: aws-cdk-lib.aws_apigateway.EndpointType
  • Default: EndpointType.REGIONAL

API Gateway endpoint type to override to.

Defaults to EndpointType.REGIONAL


SplitVpcEvenlyProps

Initializer

import { SplitVpcEvenlyProps } from '@cdklabs/cdk-enterprise-iac'

const splitVpcEvenlyProps: SplitVpcEvenlyProps = { ... }

Properties

Name Type Description
routeTableId string Route Table ID that will be attached to each subnet created.
vpcCidr string CIDR range of the VPC you're populating.
vpcId string ID of the existing VPC you're trying to populate.
cidrBits string cidrBits argument for the Fn::Cidr Cloudformation intrinsic function.
numberOfAzs number Number of AZs to evenly split into.
subnetType aws-cdk-lib.aws_ec2.SubnetType No description.

routeTableIdRequired
public readonly routeTableId: string;
  • Type: string

Route Table ID that will be attached to each subnet created.


vpcCidrRequired
public readonly vpcCidr: string;
  • Type: string

CIDR range of the VPC you're populating.


vpcIdRequired
public readonly vpcId: string;
  • Type: string

ID of the existing VPC you're trying to populate.


cidrBitsOptional
public readonly cidrBits: string;
  • Type: string
  • Default: '6'

cidrBits argument for the Fn::Cidr Cloudformation intrinsic function.


numberOfAzsOptional
public readonly numberOfAzs: number;
  • Type: number
  • Default: 3

Number of AZs to evenly split into.


subnetTypeOptional
public readonly subnetType: SubnetType;
  • Type: aws-cdk-lib.aws_ec2.SubnetType
  • Default: subnetType.PRIVATE

SubnetConfig

Initializer

import { SubnetConfig } from '@cdklabs/cdk-enterprise-iac'

const subnetConfig: SubnetConfig = { ... }

Properties

Name Type Description
availabilityZone string Which availability zone the subnet should be in.
cidrRange string Cidr range of the subnet to create.
groupName string Logical group name of a subnet.
subnetType aws-cdk-lib.aws_ec2.SubnetType What SubnetType to use.

availabilityZoneRequired
public readonly availabilityZone: string;
  • Type: string

Which availability zone the subnet should be in.


cidrRangeRequired
public readonly cidrRange: string;
  • Type: string

Cidr range of the subnet to create.


groupNameRequired
public readonly groupName: string;
  • Type: string

Logical group name of a subnet.


Example

db
subnetTypeRequired
public readonly subnetType: SubnetType;
  • Type: aws-cdk-lib.aws_ec2.SubnetType

What SubnetType to use.

This will govern the aws-cdk:subnet-type tag on the subnet

SubnetType aws-cdk:subnet-type tag value
PRIVATE_ISOLATED 'Isolated'
PRIVATE_WITH_EGRESS 'Private'
PUBLIC 'Public'

Classes

AddCfnInitProxy

  • Implements: aws-cdk-lib.IAspect

Add proxy configuration to Cloudformation helper functions.

Initializers

import { AddCfnInitProxy } from '@cdklabs/cdk-enterprise-iac'

new AddCfnInitProxy(props: AddCfnInitProxyProps)
Name Type Description
props AddCfnInitProxyProps No description.

propsRequired

Methods

Name Description
visit All aspects can visit an IConstruct.

visit
public visit(node: IConstruct): void

All aspects can visit an IConstruct.

nodeRequired
  • Type: constructs.IConstruct

AddLambdaEnvironmentVariables

  • Implements: aws-cdk-lib.IAspect

Add one or more environment variables to all lambda functions within a scope.

Initializers

import { AddLambdaEnvironmentVariables } from '@cdklabs/cdk-enterprise-iac'

new AddLambdaEnvironmentVariables(props: {[ key: string ]: string})
Name Type Description
props {[ key: string ]: string} : string} props - Key Value pair(s) for environment variables to add to all lambda functions.

propsRequired
  • Type: {[ key: string ]: string}

: string} props - Key Value pair(s) for environment variables to add to all lambda functions.


Methods

Name Description
visit All aspects can visit an IConstruct.

visit
public visit(node: IConstruct): void

All aspects can visit an IConstruct.

nodeRequired
  • Type: constructs.IConstruct

AddPermissionBoundary

  • Implements: aws-cdk-lib.IAspect

A patch for Adding Permissions Boundaries to all IAM roles.

Additional options for adding prefixes to IAM role, policy and instance profile names

Can account for non commercial partitions (e.g. aws-gov, aws-cn)

Initializers

import { AddPermissionBoundary } from '@cdklabs/cdk-enterprise-iac'

new AddPermissionBoundary(props: AddPermissionBoundaryProps)
Name Type Description
props AddPermissionBoundaryProps No description.

propsRequired

Methods

Name Description
checkAndOverride No description.
visit All aspects can visit an IConstruct.

checkAndOverride
public checkAndOverride(node: CfnResource, prefix: string, length: number, cfnProp: string, cdkProp?: string): void
nodeRequired
  • Type: aws-cdk-lib.CfnResource

prefixRequired
  • Type: string

lengthRequired
  • Type: number

cfnPropRequired
  • Type: string

cdkPropOptional
  • Type: string

visit
public visit(node: IConstruct): void

All aspects can visit an IConstruct.

nodeRequired
  • Type: constructs.IConstruct

RemovePublicAccessBlockConfiguration

  • Implements: aws-cdk-lib.IAspect

Looks for S3 Buckets, and removes the PublicAccessBlockConfiguration property.

For use in regions where Cloudformation doesn't support this property

Initializers

import { RemovePublicAccessBlockConfiguration } from '@cdklabs/cdk-enterprise-iac'

new RemovePublicAccessBlockConfiguration()
Name Type Description

Methods

Name Description
visit All aspects can visit an IConstruct.

visit
public visit(node: IConstruct): void

All aspects can visit an IConstruct.

nodeRequired
  • Type: constructs.IConstruct

RemoveTags

  • Implements: aws-cdk-lib.IAspect

Patch for removing tags from a specific Cloudformation Resource.

In some regions, the 'Tags' property isn't supported in Cloudformation. This patch makes it easy to remove

Example

// Remove tags on a resource
Aspects.of(stack).add(new RemoveTags({
  cloudformationResource: 'AWS::ECS::Cluster',
}));
// Remove tags without the standard 'Tags' name
Aspects.of(stack).add(new RemoveTags({
  cloudformationResource: 'AWS::Backup::BackupPlan',
   tagPropertyName: 'BackupPlanTags',
}));

Initializers

import { RemoveTags } from '@cdklabs/cdk-enterprise-iac'

new RemoveTags(props: RemoveTagsProps)
Name Type Description
props RemoveTagsProps No description.

propsRequired

Methods

Name Description
visit All aspects can visit an IConstruct.

visit
public visit(node: IConstruct): void

All aspects can visit an IConstruct.

nodeRequired
  • Type: constructs.IConstruct

SetApiGatewayEndpointConfiguration

  • Implements: aws-cdk-lib.IAspect

Override RestApis to use a set endpoint configuration.

Some regions don't support EDGE endpoints, and some enterprises require specific endpoint types for RestApis

Initializers

import { SetApiGatewayEndpointConfiguration } from '@cdklabs/cdk-enterprise-iac'

new SetApiGatewayEndpointConfiguration(props?: SetApiGatewayEndpointConfigurationProps)
Name Type Description
props SetApiGatewayEndpointConfigurationProps No description.

propsOptional

Methods

Name Description
visit All aspects can visit an IConstruct.

visit
public visit(node: IConstruct): void

All aspects can visit an IConstruct.

nodeRequired
  • Type: constructs.IConstruct

Enums

ProxyType

Whether an http-proxy or https-proxy.

Members

Name Description
HTTP --http-proxy.
HTTPS --https-proxy.

HTTP

-http-proxy.


HTTPS

-https-proxy.


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

cdklabs.cdk-enterprise-iac-0.0.61.tar.gz (112.9 kB view hashes)

Uploaded Source

Built Distribution

Supported by

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