Quick and easy way to access AWS Secrets Manager with Node (async)
This is also the answer to “where to keep credentials for lambda functions” ;)
Good practice while working with AWS is to keep your sensitive data in the right place. Some people would say that ie: keeping that in environment variables in Lambda is secure enough and I would say why not utilize a more secure way with Secrets Manager? The argument would be that it adds a lot of additional boilerplate code to just get some “string”… yeah, it adds, but I would not say its unnecessary. Accessing Secrets Manager is super simple.
I will use a simple lambda as an example. Code examples tested on Node.js 12.x.
First of all, we create some typical util library function to get the data out of the service — let’s call the file getSecret.js:
Then in your main lambda index.js:
Hope this sheds a bit of light on how easy is to use AWS Secrets Manager in your code — in this case when you use node.js and want it to be asynchronous.