11const mysql = require ( 'mysql2' )
2- const AWS = require ( 'aws-sdk' )
2+ const { SecretsManagerClient , GetSecretValueCommand } = require ( '@ aws-sdk/client-secrets-manager ' )
33require ( 'dotenv' ) . config ( ) ;
44
55// the env AWS_ENDPOINT_URL is automatically injected and available
@@ -8,11 +8,13 @@ const url = new URL(endpoint);
88const hostname = url . hostname ;
99
1010// configure the secretsmanager to connect to the running LocalStack instance
11- const secrets = new AWS . SecretsManager ( {
11+ const secrets = new SecretsManagerClient ( {
1212 endpoint : endpoint ,
13- accessKeyId : 'test' ,
14- secretAccessKey : 'test' ,
15- region : 'us-east-1' ,
13+ credentials : {
14+ accessKeyId : 'test' ,
15+ secretAccessKey : 'test'
16+ } ,
17+ region : 'us-east-1'
1618} )
1719
1820// the function expects "secretName" and "sqlQuery" as payload
@@ -59,12 +61,12 @@ function query (connection, sql) {
5961 } )
6062}
6163
62- function getSecretValue ( secretId ) {
63- return new Promise ( ( resolve , reject ) => {
64- secrets . getSecretValue ( { SecretId : secretId } , ( err , data ) => {
65- if ( err ) return reject ( err )
66-
67- return resolve ( JSON . parse ( data . SecretString ) )
68- } )
69- } )
64+ async function getSecretValue ( secretId ) {
65+ try {
66+ const command = new GetSecretValueCommand ( { SecretId : secretId } )
67+ const response = await secrets . send ( command )
68+ return JSON . parse ( response . SecretString )
69+ } catch ( error ) {
70+ throw error
71+ }
7072}
0 commit comments