Establishes a connection to an RDS database by utilizing a database information object and an AWS Secret Manager secret object.
Arguments
- database
A database information object, obtained from
rds_get_database(). This object includes essential details such as the database engine, username, and endpoint necessary to initiate a connection.- secret
An object obtained from AWS Secret Manager containing the credentials needed for the database connection. This object must contain a
usernameandpasswordfilds and can be retrieved viasecretManager_get_secret(), or it may be manually created if necessary.
Value
Returns an active database connection object created via
DBI::dbConnect().
Examples
if (FALSE) { # \dontrun{
con <- rds_connect_to_database(
database = rds_get_database("my-database-id"),
secret = secretManager_get_secret("my-secret")
)
## Here's how to connect to the Overquota database.
database <- rds_get_database("overquotas")
secret <- secretManager_get_secret("overquotas-secret")
con <-
DBI::dbConnect(
drv = RPostgres::Postgres(),
dbname = "postgres",
host = database$Endpoint$Address,
port = database$Endpoint$Port,
user = secret$username,
password = secret$password
)
} # }