CFML Datasource from AWS Secrets Manager
This file contains 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
this.datasource = 'appdsn_exactoritos'; | |
this.datasources["appdsn_exactoritos"] = getDatabaseConfig(); | |
private struct function getDatabaseConfig() { | |
var sys = CreateObject("java", "java.lang.System"); | |
var db_is_configured = sys.getProperty("com.app.db_is_configured"); | |
if( isNull( db_is_configured ) ) { | |
var aws = new modules.awscfml.aws(); | |
var secret_response = aws.secretsmanager.GetSecretValue( '/path/to/secret/db_access' ); | |
var db_secret_value = secret_response.data.SecretString; | |
var db_access = deserializeJSON(db_access_value); | |
sys.setProperty("com.app.db_host", db_access.host ); | |
sys.setProperty("com.app.db_port", db_access.port ); | |
sys.setProperty("com.app.db_name", db_access.dbname ); | |
sys.setProperty("com.app.db_username", db_access.username ); | |
sys.setProperty("com.app.db_password", db_access.password ); | |
sys.setProperty("com.app.db_connection_string", "jdbc:postgresql://#db_access.host#:#db_access.port#/#db_access.dbname#" ); | |
sys.setProperty("com.app.db_is_configured", true ); | |
} | |
// example for Lucee CFML - Adobe ColdFusion syntax would be different | |
return { | |
class: 'org.postgresql.Driver' | |
, bundleName: 'org.postgresql.jdbc' | |
, bundleVersion: '42.2.20' | |
, connectionString: sys.getProperty("com.app.db_connection_string") | |
, username: sys.getProperty("com.app.db_username") | |
, password: sys.getProperty("com.app.db_password") | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment