【发布时间】:2021-07-13 04:58:12
【问题描述】:
我想使用 lambda 函数停止多个 RDS 实例。我使用的代码是:
import sys
import botocore
import boto3
from botocore.exceptions import ClientError
def lambda_handler(event, context):
rds = boto3.client('rds')
lambdaFunc = boto3.client('lambda')
print('Trying to get Environment variable')
try:
funcResponse = lambdaFunc.get_function_configuration(
FunctionName='lambdaStopRDS'
)
DBinstance = funcResponse['Environment']['Variables']['DBInstanceName']
print('Stopping RDS service for DBInstance : ' + DBinstance)
except ClientError as e:
print(e)
try:
response = rds.stop_db_instance(
DBInstanceIdentifier=DBinstance
)
print('Success :: ')
return response
except ClientError as e:
print(e)
return
{
'message' : "Script execution completed. See Cloudwatch logs for complete output"
}
我正在添加以下环境变量:
键:DBInstanceName 值:database-1,database-2
并得到以下错误:
Trying to get Environment variable
Stopping RDS service for DBInstance : database-1, database-2
An error occurred (InvalidParameterValue) when calling the StopDBInstance operation: Invalid database identifier: database-1, database-2
这里,Keys 必须是唯一的,所以我不能添加另一个同名的 key 并添加另一个 RDS。 有什么方法可以在没有标签的情况下停止同一 VPC/区域内的多个 RDS 实例?
【问题讨论】:
标签: amazon-web-services aws-lambda boto3 amazon-rds