Skip to content

Instantly share code, notes, and snippets.

@mjclemente
Created January 18, 2022 14:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjclemente/5a1c788c20e5a3e91b77f33d08d82934 to your computer and use it in GitHub Desktop.
Save mjclemente/5a1c788c20e5a3e91b77f33d08d82934 to your computer and use it in GitHub Desktop.
CFML Datasource from AWS Secrets Manager
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