Last active
May 12, 2019 00:22
-
-
Save duncangh/acd3a5674d67388c53f3d45aa77916b6 to your computer and use it in GitHub Desktop.
RDS SQLAlchemy Connection Strings (if all of your databases are postgreSQL)
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
# I'm a one trick pony, but I can do ec2 conns too | |
import boto3 | |
ec2 = boto3.client('ec2') | |
instances : list = ec2.describe_instances()['Reservations'] | |
def _make_string_from_instance(instance): | |
key_name = instance['KeyName'] | |
public_dns_name = instance['NetworkInterfaces'][0]['Association']['PublicDnsName'] | |
return f"ssh -i ~/{key_name}.pem.txt ec2-user@{public_dns_name}" | |
for instance in instances: | |
instance = instance['Instances'][0] | |
connection_string = _make_string_from_instance(instance) | |
print(connection_string) |
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 boto3 | |
rds = boto3.client('rds') | |
instances = rds.describe_db_instances()['DBInstances'] | |
password = input("database_password: ") | |
def _make_string_from_instance(instance, password=password): | |
host_name = instance['Endpoint']['Address'] | |
db_name = instance['DBName'] | |
user_name = instance['MasterUsername'] | |
port = instance['Endpoint']['Port'] | |
return f"postgresql+psycopg2://{user_name}:{password}@{host_name}:{port}/{db_name}" | |
for instance in instances: | |
connection_string = _make_string_from_instance(instance) | |
print(connection_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment