Created
March 10, 2024 15:26
-
-
Save ensean/41dd14bca948bb1df44ca0bfca26b3e0 to your computer and use it in GitHub Desktop.
lambda modify aurora serverless acu
This file contains hidden or 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
import json | |
import boto3 | |
client = boto3.client('rds') | |
def modify_acu(cluster_id, min_acu, max_acu): | |
resp = client.modify_db_cluster( | |
DBClusterIdentifier=cluster_id, | |
ApplyImmediately=True, | |
ServerlessV2ScalingConfiguration={ | |
'MinCapacity': min_acu, | |
'MaxCapacity': max_acu | |
} | |
) | |
return resp | |
def lambda_handler(event, context): | |
cluster_id = event.get('cluster_id', None) | |
min_acu = event.get('min_acu', 0) | |
max_acu = event.get('max_acu', 0) | |
if cluster_id is None or min_acu == 0 or max_acu == 0: | |
return { | |
'statusCode': 401, | |
'body': json.dumps('Parameter error.') | |
} | |
resp = modify_acu(cluster_id, min_acu, max_acu) | |
return { | |
'statusCode': 200, | |
'body': json.dumps('Cluster updated') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
通过 boto3 SDK 配置 Aurora Serverless V2 的 ACU,实现主动扩容