|
2 | 2 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
3 | 3 | // SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
| 5 | +// snippet-start:[php.example_code.ec2.service.Ec2Service] |
| 6 | + |
5 | 7 | namespace Ec2; |
6 | 8 |
|
7 | 9 | use Aws\Ec2\Ec2Client; |
@@ -46,54 +48,91 @@ public function __construct($client = null, $region = 'us-west-2', $version = 'l |
46 | 48 | */ |
47 | 49 | public function createVpcEndpoint(string $serviceName, string $vpcId, array $routeTableIds): array |
48 | 50 | { |
49 | | - $result = $this->ec2Client->createVpcEndpoint([ |
50 | | - 'ServiceName' => $serviceName, |
51 | | - 'VpcId' => $vpcId, |
52 | | - 'RouteTableIds' => $routeTableIds, |
53 | | - ]); |
54 | | - |
55 | | - return $result["VpcEndpoint"]; |
| 51 | + try { |
| 52 | + $result = $this->ec2Client->createVpcEndpoint([ |
| 53 | + 'ServiceName' => $serviceName, |
| 54 | + 'VpcId' => $vpcId, |
| 55 | + 'RouteTableIds' => $routeTableIds, |
| 56 | + ]); |
| 57 | + |
| 58 | + return $result["VpcEndpoint"]; |
| 59 | + } catch(Ec2Exception $caught){ |
| 60 | + echo "There was a problem creating the VPC Endpoint: {$caught->getAwsErrorMessage()}\n"; |
| 61 | + throw $caught; |
| 62 | + } |
56 | 63 | } |
57 | 64 |
|
58 | 65 | // snippet-end:[php.example_code.ec2.service.createVpcEndpoint] |
59 | 66 |
|
60 | 67 | // snippet-start:[php.example_code.ec2.service.createVpc] |
61 | 68 |
|
62 | | - public function createVpc($cidr) |
| 69 | + /** |
| 70 | + * @param string $cidr |
| 71 | + * @return array |
| 72 | + */ |
| 73 | + public function createVpc(string $cidr): array |
63 | 74 | { |
64 | | - $result = $this->ec2Client->createVpc([ |
65 | | - "CidrBlock" => $cidr, |
66 | | - ]); |
67 | | - return $result['Vpc']; |
| 75 | + try { |
| 76 | + $result = $this->ec2Client->createVpc([ |
| 77 | + "CidrBlock" => $cidr, |
| 78 | + ]); |
| 79 | + return $result['Vpc']; |
| 80 | + }catch(Ec2Exception $caught){ |
| 81 | + echo "There was a problem creating the VPC: {$caught->getAwsErrorMessage()}\n"; |
| 82 | + throw $caught; |
| 83 | + } |
68 | 84 | } |
69 | 85 |
|
70 | 86 | // snippet-end:[php.example_code.ec2.service.createVpc] |
71 | 87 |
|
72 | 88 | // snippet-start:[php.example_code.ec2.service.deleteVpc] |
73 | 89 |
|
74 | | - public function deleteVpc(mixed $vpcId) |
| 90 | + /** |
| 91 | + * @param string $vpcId |
| 92 | + * @return void |
| 93 | + */ |
| 94 | + public function deleteVpc(string $vpcId) |
75 | 95 | { |
76 | | - $result = $this->ec2Client->deleteVpc([ |
77 | | - "VpcId" => $vpcId, |
78 | | - ]); |
| 96 | + try { |
| 97 | + $this->ec2Client->deleteVpc([ |
| 98 | + "VpcId" => $vpcId, |
| 99 | + ]); |
| 100 | + }catch(Ec2Exception $caught){ |
| 101 | + echo "There was a problem deleting the VPC: {$caught->getAwsErrorMessage()}\n"; |
| 102 | + throw $caught; |
| 103 | + } |
79 | 104 | } |
80 | 105 |
|
81 | 106 | // snippet-end:[php.example_code.ec2.service.deleteVpc] |
82 | 107 |
|
83 | 108 | // snippet-start:[php.example_code.ec2.service.deleteVpcEndpoint] |
84 | 109 |
|
85 | | - public function deleteVpcEndpoint(mixed $vpcEndpointId) |
| 110 | + /** |
| 111 | + * @param string $vpcEndpointId |
| 112 | + * @return void |
| 113 | + */ |
| 114 | + public function deleteVpcEndpoint(string $vpcEndpointId) |
86 | 115 | { |
87 | | - $result = $this->ec2Client->deleteVpcEndpoints([ |
88 | | - "VpcEndpointIds" => [$vpcEndpointId], |
89 | | - ]); |
| 116 | + try { |
| 117 | + $this->ec2Client->deleteVpcEndpoints([ |
| 118 | + "VpcEndpointIds" => [$vpcEndpointId], |
| 119 | + ]); |
| 120 | + }catch (Ec2Exception $caught){ |
| 121 | + echo "There was a problem deleting the VPC Endpoint: {$caught->getAwsErrorMessage()}\n"; |
| 122 | + throw $caught; |
| 123 | + } |
90 | 124 | } |
91 | 125 |
|
92 | 126 | // snippet-end:[php.example_code.ec2.service.deleteVpcEndpoint] |
93 | 127 |
|
94 | 128 | // snippet-start:[php.example_code.ec2.service.describeRouteTables] |
95 | 129 |
|
96 | | - public function describeRouteTables(array $routeTableIds = [], array $filters = []) |
| 130 | + /** |
| 131 | + * @param array $routeTableIds |
| 132 | + * @param array $filters |
| 133 | + * @return array |
| 134 | + */ |
| 135 | + public function describeRouteTables(array $routeTableIds = [], array $filters = []): array |
97 | 136 | { |
98 | 137 | $parameters = []; |
99 | 138 | if($routeTableIds){ |
@@ -121,17 +160,26 @@ public function describeRouteTables(array $routeTableIds = [], array $filters = |
121 | 160 |
|
122 | 161 | // snippet-start:[php.example_code.ec2.service.waitForVpcAvailable] |
123 | 162 |
|
124 | | - public function waitForVpcAvailable(string $VpcId) |
| 163 | + /** |
| 164 | + * @param string $VpcId |
| 165 | + * @return void |
| 166 | + */ |
| 167 | + public function waitForVpcAvailable(string $VpcId): void |
125 | 168 | { |
126 | | - |
127 | | - $waiter = $this->ec2Client->getWaiter("VpcAvailable", [ |
128 | | - 'VpcIds' => [$VpcId], |
129 | | - ]); |
130 | | - |
131 | | - $promise = $waiter->promise(); |
132 | | - $promise->wait(); |
133 | | - |
| 169 | + try { |
| 170 | + $waiter = $this->ec2Client->getWaiter("VpcAvailable", [ |
| 171 | + 'VpcIds' => [$VpcId], |
| 172 | + ]); |
| 173 | + |
| 174 | + $promise = $waiter->promise(); |
| 175 | + $promise->wait(); |
| 176 | + }catch(Ec2Exception $caught){ |
| 177 | + echo "There was a problem waiting for the VPC: {$caught->getAwsErrorMessage()}\n"; |
| 178 | + throw $caught; |
| 179 | + } |
134 | 180 | } |
135 | 181 |
|
136 | 182 | // snippet-end:[php.example_code.ec2.service.waitForVpcAvailable] |
137 | 183 | } |
| 184 | + |
| 185 | +// snippet-end:[php.example_code.ec2.service.Ec2Service] |
0 commit comments