22# -*- encoding: utf-8 -*-
33# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab
44
5+ import os
56import aws_cdk as cdk
67
78from aws_cdk import (
@@ -23,27 +24,27 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
2324 # for example,
2425 # cdk -c vpc_name=your-existing-vpc syth
2526 #
26- # vpc_name = self.node.try_get_context("vpc_name") or "default"
27- # vpc = aws_ec2.Vpc.from_lookup(self, "OpenSearchDomainVpc",
28- # is_default=True ,
29- # vpc_name=vpc_name)
30-
31- #XXX: To use more than 2 AZs, be sure to specify the account and region on your stack.
32- #XXX: https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_ec2/Vpc.html
33- vpc = aws_ec2 . Vpc ( self , "OpenSearchDomainVpc" ,
34- max_azs = 3 ,
35- gateway_endpoints = {
36- "S3" : aws_ec2 . GatewayVpcEndpointOptions (
37- service = aws_ec2 .GatewayVpcEndpointAwsService . S3
38- )
39- }
40- )
41-
42- self . vpc = vpc
27+ if str ( os . environ . get ( 'USE_DEFAULT_VPC' , 'false' )). lower () == 'true' :
28+ vpc_name = self . node . try_get_context ( "vpc_name" ) or "default"
29+ self . vpc = aws_ec2 . Vpc . from_lookup ( self , "OpenSearchDomainVpc" ,
30+ is_default = True ,
31+ vpc_name = vpc_name )
32+ else :
33+ #XXX: To use more than 2 AZs, be sure to specify the account and region on your stack.
34+ #XXX: https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_ec2/ Vpc.html
35+ self . vpc = aws_ec2 . Vpc ( self , "OpenSearchDomainVpc" ,
36+ max_azs = 3 ,
37+ gateway_endpoints = {
38+ "S3" : aws_ec2 .GatewayVpcEndpointOptions (
39+ service = aws_ec2 . GatewayVpcEndpointAwsService . S3
40+ )
41+ }
42+ )
43+
4344
4445 #XXX: The Name field of every Export member must be specified and
4546 # consist only of alphanumeric characters,colons, or hyphens.
4647 cdk .CfnOutput (self , 'VPCID' ,
4748 value = self .vpc .vpc_id ,
48- export_name = '{ }-VPCID'. format ( self . stack_name ) )
49+ export_name = f' { self . stack_name } -VPCID' )
4950
0 commit comments