-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automatically increase service quotas if reached for routes and auth …
…rules (#13)
- Loading branch information
1 parent
1b44daa
commit fed37e2
Showing
11 changed files
with
141 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
lib/cfnvpn/templates/lambdas/auto_route_populator/quotas.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import boto3 | ||
|
||
ROUTE_TABLE_QUOTA_CODE = 'L-401D78F7' | ||
AUTH_RULE_TABLE_QUOTA_CODE = 'L-9A1BC94B' | ||
EC2_SERVICE_CODE = 'ec2' | ||
IN_PROGRESS = ['PENDING', 'CASE_OPENED'] | ||
|
||
def get_route_count(endpoint) -> int: | ||
client = boto3.client('ec2') | ||
response = client.describe_client_vpn_routes( | ||
ClientVpnEndpointId=endpoint, | ||
) | ||
return len(response['Routes']) | ||
|
||
def quota_request_open(quota_code) -> bool: | ||
client = boto3.client('service-quotas') | ||
response = client.list_requested_service_quota_change_history_by_quota( | ||
ServiceCode=EC2_SERVICE_CODE, | ||
QuotaCode=quota_code | ||
) | ||
# Status='PENDING'|'CASE_OPENED'|'APPROVED'|'DENIED'|'CASE_CLOSED' | ||
return any(req['status'] in IN_PROGRESS for req in response['RequestedQuotas']) | ||
|
||
def increase_quota(increase_value, quota_code, endpoint) -> str: | ||
if quota_request_open(quota_code): | ||
return None | ||
|
||
current_route_count = get_route_count(endpoint) | ||
desired_value = current_route_count + increase_value | ||
|
||
client = boto3.client('service-quotas') | ||
response = client.request_service_quota_increase( | ||
ServiceCode=EC2_SERVICE_CODE, | ||
QuotaCode=quota_code, | ||
DesiredValue=desired_value | ||
) | ||
return response['CaseId'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters