How to get secret from Secret Manager in serverless - server

I configured a secret to my RDS database. Its name is: qa/aurora
I am trying to make the reference on my serverless.yml in the environment settings like this:
DB: ${ssm:/aws/reference/secretsmanager/qa/aurora~true}
I want to use this DB environment variable to set the user and password to my Aurora database.
The problem is that I am getting this error:
ServerlessError: An error occurred: testLambdaFunction - Properties validation failed for resource testLambdaFunction with message:
#/Environment/Variables/DB: expected type: String, found: JSONObject.
at C:\Users\fer\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\lib\monitorStack.js:94:23
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async AwsDeploy.update (C:\Users\fer\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\lib\updateStack.js:144:5)
According to the Serverless docs, it should be working fine with getting a JSONObject.
What I am missing to make this work?
PS: Why should I add ~true at the end of the string to find the secret? If I remove this value i get the error:
A valid SSM parameter to satisfy the declaration 'ssm:/aws/reference/secretsmanager/qa/aurora' could not be found.

The problema was that i was nesting the 3 levels down the code:
DB: ${ssm:/aws/reference/secretsmanager/qa/aurora~true}
As soon as i change it to the same level of the environment attribute it worked

Related

Unable to connect to OrientDB - "Error in database URL: the engine was not specified"

Trying to connect to a new OrientDB (v3.2.15) database in Docker:
connect env remote:localhost root root;
create database apples plocal;
But am getting:
Error: com.orientechnologies.orient.core.exception.OConfigurationException: Error in database URL: the engine was not specified. Syntax is: <engine>:<db-type>:<db-name>[?<db-param>=<db-value>[&]]*. URL was: apples
Looking at the source code I can see : is required, or it'll through an exception - but the documentation says the opposite and my commands look correct.
Any ideas what I'm doing wrong, please?

flyway error: Unable to obtain connection from database for user 'null'

im trying to run flyway docker image 7.3.2 against a postgres db on kubernetes:
When i run the job my output is:
Flyway Community Edition 7.3.2 by Redgate
ERROR:
Unable to obtain connection from database (jdbc:postgresql://xxx.eu-west-2.rds.amazonaws.com:5432/xxx flyway.user=postgres flyway.password=****************) for user 'null': The server requested password-based authentication, but no password was provided.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL State : 08004
Error Code : 0
Message : The server requested password-based authentication, but no password was provided.
Caused by: org.postgresql.util.PSQLException: The server requested password-based authentication, but no password was provided.
the settings it outputs are correct and should enable a connection.
I pass in my flyway.conf via a configmap which is:
apiVersion: v1
kind: ConfigMap
metadata:
name: flyway-configmap
data:
flyway.conf:
flyway.url=jdbc:postgresql://xxx.eu-west-2.rds.amazonaws.com:5432/xxx
flyway.user=postgres
flyway.password=xxx
anyone able to assist in what im doing wrong?
If that is literally your ConfigMap, then it is missing the | character after the : which would make that yaml key into a newline delimited scalar. That theory also squares up with your error message showing that the entire thing is taken as the value of flyway.url
What you want:
flyway.conf: |
flyway.url=jdbc:postgresql://xxx.eu-west-2.rds.amazonaws.com:5432/xxx
flyway.user=postgres
flyway.password=xxx

CraftCMS with Redis: Failed to open redis DB connection (tcp://:, database=): 0 - Failed to parse address ":"

I have yii2 and yii2-redis installed on a CraftCMS project, but when I fire up the project, I get an error message that reads:
Database Exception – yii\db\Exception
Failed to open redis DB connection (tcp://:, database=): 0 - Failed to parse address ":"
Error Info: Failed to parse address ":"
I'm not quite sure what to do with this error. In my .env file, I put in:
REDIS_HOST=localhost
REDIS_PORT=3306
REDIS_PASSWORD=
REDIS_KEY_PREFIX=craft
But that only yielded a different error:
Database Exception – yii\db\Exception
Failed to open redis DB connection (tcp://:3306, database=): 0 - php_network_getaddresses:
getaddrinfo failed: nodename nor servname provided, or not known
Error Info: php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
Help?
Additional context: I didn't set up the build for this project, so I more or less inherited this Redis setup.
Update:
I went and dug into the config file for the Redis setup and found a misnaming between the .env variables and what was present in the .env file. Now I'm getting a completely different error:
"Received illegal data from redis: Redis command was: SELECT 0"
Please check that your configuration matches the environment variables you use.
Turns out I'd deleted the Redis database (don't remember how or when), so creating a new one (with the correct .env variables set) fixed the problem immediately.
Whew.

MongoDB unescaped slash in user info section while building a serverless function hosted by Vercel

I'm hosting a website with Vercel, built in React and with serverless functions through them.
I've created a function that posts to my MongoDB database using Mongoose.
However, I can't connect to my database - it comes up with the following error:
c5021f92-4dcc-49de-89c9-7a00203be4e0 ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"MongoParseError: Unescaped slash in userinfo section","reason":{"errorType":"MongoParseError","errorMessage":"Unescaped slash in userinfo section","name":"MongoParseError","stack":["MongoParseError: Unescaped slash in userinfo section"," at parseConnectionString (/var/task/node_modules/mongodb/lib/core/uri_parser.js:603:21)"," at QueryReqWrap.callback (/var/task/node_modules/mongodb/lib/core/uri_parser.js:114:7)"," at QueryReqWrap.onresolve [as oncomplete] (dns.js:205:10)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: MongoParseError: Unescaped slash in userinfo section"," at process.<anonymous> (/var/runtime/index.js:35:15)"," at process.emit (events.js:327:22)"," at processPromiseRejections (internal/process/promises.js:209:33)"," at processTicksAndRejections (internal/process/task_queues.js:98:32)"]}
Unknown application error occurred
I've built my connection string like this, after doing some research into environment variables and MongoDB with Vercel.
mongoose.connect(`mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}#database.f9twk.mongodb.net/#otter-money?retryWrites=true&w=majority`, {useNewUrlParser: true});
My question is a) what am I doing wrong in that string? I'm using template literals so not sure why it's not happy with it. and b) is there a better way to approach this?
I've tried the full string as a mongoURI in my env, but no luck.
The '#' in the database name confuses the parser. You need to escape it:
database.f9twk.mongodb.net/%40otter-money
The better way is to pass connection parameters in options:
mongoose.connect("mongodb+srv://database.f9twk.mongodb.net/",
{
useNewUrlParser: true,
user: process.env.MONGO_USER,
pass: process.env.MONGO_PASSWORD,
dbName: "#otter-money",
retryWrites: true,
w: "majority"
});

SailsJS MongoDB Database connection error

I am new for SailsJS. I am trying to create database connection with mongo but it shows error like this
A hook (`orm`) failed to load!
error: Error: Consistency violation: A model (`sleep`) references a datastore which cannot be found (`mongo`).
If this model definition has an explicit `connection` property, check that it is spelled correctly.
If not, check your default `connection` (usually located in `config/models.js`).
Finally, check that this connection (`mongo`) is valid as per http://sailsjs.org/documentation/reference/configuration/sails-config-connections.
Your model is connecting to an invalid connection 'mongo'.
Check the connection either in you model 'Sleep' or in config/models.js