Creates a new Amazon VPC with the specified CIDR block. :param cidr_block: The CIDR block for the new VPC, such as '10.0.0.0/16'. :return: The ID of the new VPC.
(self, cidr_block: str)
| 38 | |
| 39 | # snippet-start:[python.example_code.ec2.CreateVpc] |
| 40 | def create(self, cidr_block: str) -> str: |
| 41 | """ |
| 42 | Creates a new Amazon VPC with the specified CIDR block. |
| 43 | |
| 44 | :param cidr_block: The CIDR block for the new VPC, such as '10.0.0.0/16'. |
| 45 | :return: The ID of the new VPC. |
| 46 | """ |
| 47 | try: |
| 48 | response = self.ec2_client.create_vpc(CidrBlock=cidr_block) |
| 49 | vpc_id = response["Vpc"]["VpcId"] |
| 50 | |
| 51 | waiter = self.ec2_client.get_waiter("vpc_available") |
| 52 | waiter.wait(VpcIds=[vpc_id]) |
| 53 | return vpc_id |
| 54 | except ClientError as client_error: |
| 55 | logging.error( |
| 56 | "Couldn't create the vpc. Here's why: %s", |
| 57 | client_error.response["Error"]["Message"], |
| 58 | ) |
| 59 | raise |
| 60 | |
| 61 | # snippet-end:[python.example_code.ec2.CreateVpc] |
| 62 |