aws_cdk.aws_ec2.vpc only utilizes 2 availability zones no matter what max_azs is set to unless you specify account number in the Stack env attribute
The VpcStack construct only sets up the right number of subnets in relation to the max_azs attribute if you pass env=Environment(account="XXXXXXX", region="us-east-1") into the stack initialization. I would like to only specify the deploy target by AWS profile on the CLI. It should not be necessary to provide account number in code for the subnet count to be correct, unless I am missing something.
Reproduction Steps
Vpc(self, self.cluster,
cidr=<adequate size for subnets>,
max_azs=3,
..
subnet_configuration=<public and private subnets configured>
)
Deploy via CLI with AWS profile specified and env=Environment(account="XXXXXXX", region="us-east-1") NOT passed into the stack initialization
cdk deploy .. --profile
Error
Subnet count is incorrect
Environment
- CLI Version : 1.22.0 (build 309ac1b)
- Framework Version: 1.22
- OS : MacOS
- Language : Python 3.6
Other
Related to #3497
I can't see how the account number would be required to calculate the right number of subnets.
This is :bug: Bug Report
Workaround I noticed the CDK CLI was setting OS environment variables based on the passed profile on the CLI. Method to build CDK Environment off of environment variables:
def get_cdk_environment():
return Environment(account=os.environ['CDK_DEFAULT_ACCOUNT'],
region=os.environ['CDK_DEFAULT_REGION'])
When initializing Stack set environment:
env=cdk_util.get_cdk_environment()
Correct number of subnets are created with this method.
I feel this has been appropriately covered in https://docs.aws.amazon.com/cdk/api/latest/docs/aws-ec2-readme.html#control-over-availability-zones
Closing.