-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ApplicationAutoscaling: put_scaling_policy() now generates CW alarms …
…(for some service-types) (#7566)
- Loading branch information
Showing
5 changed files
with
424 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
from functools import wraps | ||
|
||
import boto3 | ||
|
||
from moto import mock_aws | ||
from tests.test_dynamodb import dynamodb_aws_verified | ||
|
||
|
||
def application_autoscaling_aws_verified(): | ||
""" | ||
Function that is verified to work against AWS. | ||
Can be run against AWS at any time by setting: | ||
MOTO_TEST_ALLOW_AWS_REQUEST=true | ||
If this environment variable is not set, the function runs in a `mock_aws` context. | ||
This decorator will: | ||
- Register a Scalable Target | ||
- Run the test | ||
- Deregister the Scalable Target | ||
""" | ||
|
||
def inner(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
allow_aws_request = ( | ||
os.environ.get("MOTO_TEST_ALLOW_AWS_REQUEST", "false").lower() == "true" | ||
) | ||
|
||
@dynamodb_aws_verified() | ||
def scalable_target_with_dynamodb_table(table_name): | ||
namespace = "dynamodb" | ||
resource_id = f"table/{table_name}" | ||
scalable_dimension = "dynamodb:table:ReadCapacityUnits" | ||
|
||
client = boto3.client( | ||
"application-autoscaling", region_name="us-east-1" | ||
) | ||
kwargs["client"] = client | ||
kwargs["namespace"] = namespace | ||
kwargs["resource_id"] = resource_id | ||
kwargs["scalable_dimension"] = scalable_dimension | ||
|
||
client.register_scalable_target( | ||
ServiceNamespace=namespace, | ||
ResourceId=resource_id, | ||
ScalableDimension=scalable_dimension, | ||
MinCapacity=1, | ||
MaxCapacity=4, | ||
) | ||
try: | ||
resp = func(*args, **kwargs) | ||
finally: | ||
client.deregister_scalable_target( | ||
ServiceNamespace=namespace, | ||
ResourceId=resource_id, | ||
ScalableDimension=scalable_dimension, | ||
) | ||
|
||
return resp | ||
|
||
if allow_aws_request: | ||
return scalable_target_with_dynamodb_table() | ||
else: | ||
with mock_aws(): | ||
return scalable_target_with_dynamodb_table() | ||
|
||
return wrapper | ||
|
||
return inner |
Oops, something went wrong.