python 最简单的boto3示例,用于创建RDS PostgreSQL实例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 最简单的boto3示例,用于创建RDS PostgreSQL实例相关的知识,希望对你有一定的参考价值。
import time
import boto3
import botocore
def main():
db_identifier = 'yourDBID'
rds = boto3.client('rds')
try:
rds.create_db_instance(DBInstanceIdentifier=db_identifier,
AllocatedStorage=200,
DBName='yourdbname',
Engine='postgres',
# General purpose SSD
StorageType='gp2',
StorageEncrypted=True,
AutoMinorVersionUpgrade=True,
# Set this to true later?
MultiAZ=False,
MasterUsername='youruser',
MasterUserPassword='yourpassword',
VpcSecurityGroupIds=['YOUR_SECURITY_GROUP_ID'],
DBInstanceClass='db.m3.2xlarge',
Tags=[{'Key': 'MyTag', 'Value': 'Hawaii'}])
print 'Starting RDS instance with ID: %s' % db_identifier
except botocore.exceptions.ClientError as e:
if 'DBInstanceAlreadyExists' in e.message:
print 'DB instance %s exists already, continuing to poll ...' % db_identifier
else:
raise
running = True
while running:
response = rds.describe_db_instances(DBInstanceIdentifier=db_identifier)
db_instances = response['DBInstances']
if len(db_instances) != 1:
raise Exception('Whoa cowboy! More than one DB instance returned; this should never happen')
db_instance = db_instances[0]
status = db_instance['DBInstanceStatus']
print 'Last DB status: %s' % status
time.sleep(5)
if status == 'available':
endpoint = db_instance['Endpoint']
host = endpoint['Address']
# port = endpoint['Port']
print 'DB instance ready with host: %s' % host
running = False
if __name__ == '__main__':
main()
以上是关于python 最简单的boto3示例,用于创建RDS PostgreSQL实例的主要内容,如果未能解决你的问题,请参考以下文章
正在寻找将 aws pig 步骤注入已经运行的 emr 的 boto3 python 示例?
python 使用boto3列出正在运行的EC2实例的示例
markdown 使用GetParameter从SSM获取秘密使用Python和Boto3的示例
boto3或aws cli是否具有从实例创建模板?
需要用于 ECS 帮助的 Python Boto3
将 Locust 与 Boto3 一起使用的示例