How to know mock postgres host name? - postgresql

I´m trying to create some unit tests on a python aws lambda proyect using moto.
I´ve created an rds postgres instance using:
#pytest.fixture(scope='function')
def rds(aws_credentials):
with mock_rds():
yield boto3.client("rds", region_name="us-west-2").create_db_instance(
DBInstanceIdentifier="db-master-1",
AllocatedStorage=10,
Engine="postgres",
DBName="fox-postgres",
DBInstanceClass="db.m1.small",
LicenseModel="license-included",
MasterUsername="postgres",
MasterUserPassword="postgres",
Port=5432,
DBSecurityGroups=["my_sg"],
VpcSecurityGroupIds=["sg-123456"],
EnableCloudwatchLogsExports=["audit", "error"],
)
How do I know (or set) the host name in order to run queries?
Is that even possible? I don´t know if this is a real (or almost) database instance.
Thanks in advance.

It is not possible to run actual queries against Moto - RDS responses are completely mocked.
Moto's describe_db_instances-method does return an endpoint in the Endpoint.Address-attribute, but this is hardcoded - see https://github.com/getmoto/moto/blob/339309c9af4188006d9592469d52193f57249b1e/moto/rds/models.py#L674

Related

Connecting Postgres instance to AppEngine - Google Cloud, with SpringBoot

I've nearly got a SpringBoot app running on Google Cloud services that is connected to a Postgres instance.
I've ran through the steps on their guide, located here and have gotten to the point where I need to set my variables up for the app to find the database instance:
The problem encountered is two fold:
I don't know where and how to set these
My server logs report this error:
meaning that the Spring application is trying to find the database like it would on my local.
I set the following values in the app.yaml (assuming this is where they should be?)
runtime: java11
instance_class: F1
env_variables:
SQL_USER: quickstart-user
SQL_PASSWORD: <password>
SQL_DATABASE: quickstart_db
INSTANCE_CONNECTION_NAME: quickstart-instance
So, my question(s) are:
Is this the correct place to set them?
If not, do I need a appengine-web.xml file instead (And does anyone have an example of what this looks like, I can't find one)
How do I stop the app from looking for the local database?
Thanks

Use AWS Amplify and App Sync with existing Node Server using Mongodb

Currently, I'm developing a native application using React-Native. I've decided to go with AWS Amplify because of it's real time updates as well as its authentication.
I also have a Web Application that runs on a Node.js with Epxress server. This web application connects to a Mongo database.
My big problem is that I would like to have all of my aws amplify queries run to my existing MongoDb instead of a new dynamoDb database which is provided with AWS AppSync, but unfortunately I dont know where to start. This is especially helpful in adding authentication easily in my existing web application as well.
My first idea was to just create all my API endpoints in a new node js server and have app sync call to these API end points, but I'm not sure how to implement calling end points on an existing server (and this seems kind of counter intuitive to the 'serverless' idea)
My other idea came from this: Can AWS App-Sync be used without dynamoDB
This states to use AWS Lambda to 'pipeline' my data to the existing mongodb, but I'm not really sure what that entails.
TL;DR - I would like to be able to query an existing Mongodb instead of using DynamoDb when using AWS Amplify with AppSync.
I hope this is clear enough and doesn't sound like I'm rambling. Thanks in advance!
I would suggest using either an HTTP datasource to connect to your MongoDB backend or a Lambda function. Here are a couple getting started tutorials for both:
https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-http-resolvers.html
https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html
If you go the Lambda route, then you can leverage the new #function feature of the GraphQL Transformer in the Amplify CLI: https://aws-amplify.github.io/docs/cli/graphql#function

Internal Server Error (500) AWS Elasticbeanstalk deployed flask app

I have deployed various versions of the app previously with no errors.
However, I had to make some modifications on two tables in my AWS RDS running PostgreSQL. alter table NAME alter column NAME type date using to_date(...)
I've done that directly on the AWS RDS and modified SQLAlchemy column accordingly. date = Column(Date)
Any API call that sends queries these two tables returns Internal Server Error - In the meantime, there are no errors in deploying this version of the app and moreover from my python interpreter running any SQLAlchemy code that queries any of these two tables always returns what's expected.
I have tried several ways to fix this. The only one that worked is to remove the line date = Column(Date) from SQLAlchemy setup file - Then there was no 500 on any API call but of course that doesn't help as I need that column!
Any help on this will be highly appreciated really...

Hosting the database separately for Meteor apps

It seems to be a common and safer practice to host the database separately from Meteor apps. That is to say, have an EC2 instance for your Meteor app, and an EC2 instance for your MongoDB, and make them talk to one another.
From what I understand, people do this because it's more secure, and it allows them to deploy newer versions of their app without touching the database.
I'd like to do this with Amazon EC2 alone, as opposed to using another 3rd party service, like Compose.io.
How can I host a Meteor app and its database separately on two EC2 instances, and have them communicate with one another?
It is common practice, and people mostly do it because it offers you the ability to scale them both independently.
As to the how, you'll want to obviously configure each of your Amazon EC2 instances, installing meteor on one, and MongoDB on the other. You'll also need to configure your VPC (Amazon Virtual Private Cloud) so that your MongoDB instance accepts incoming connections on whatever port you specify (default is 27017), so that your Meteor Application can connect.
After that it's just a matter of telling your meteor app where to go to get the database connection. The most secure way of doing this will be to set a couple Environment Variables, named MONGODBSERVER and MONGODBPORT, DBUSER, DBPASSWORD, etc.
You'll then want to set some variables in your server Meteor code, using something like:
Meteor.startup(function() {
var DbUser = process.env.DBUSER;
var DbPassword = process.env.DBPASSWORD;
var MongoDBServer = process.env.MONGODBSERVER;
var MongoDBPort = process.env.MONGODBPORT;
});
And if you're using the native MongoDB Driver, connecting becomes trivial:
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://DbUser:DbPassword#MongoDBServer:MongoDBPort/databasename', function(err, db) {
...
});
Then it's just a matter of constructing your Mongo models using something like:
Temperatures = new Mongo.Collection('temperatures');
Temperatures._ensureIndex({temp: 1, time: 1});
And then taking action on those models in regard to the database:
Temperatures.insert({temp: ftemp, time: Math.floor(Date.now() / 1000)});
I'll also mention that http://modulus.io is a really decent Meteor hosting solution. I'd recommend them, unless you are stuck on using Amazon EC2 instances, which is fine, but more complicated for a simple application.
You need to set an Environment Variable for Mongo where it is hosted
MONGO_URL
mongodb://:#hostingproviderurl:port/xxx?autoReconnect=true&connectTimeoutMS=60000
the correct mongodb:// url string would be provided by the mongodb hosting provider.

Scala Lift - Connect to remote MongoDB

I currently have my app running on my local machine, in Boot.scala I have:
MongoDB.defineDb(
DefaultMongoIdentifier,
MongoAddress(MongoHost("127.0.0.1", 27017), "platform")
)
I've successfully deployed the app to a cloud provider, and am in the process of setting up a database # mongohq.com
What would I need to change to enable the app to connect? I've taken a look here:
https://www.assembla.com/wiki/show/liftweb/Mongo_Configuration
But am a little confused by the connection details provided by mongohq, all they provide is:
Mongo URI
mongodb://<user>:<password>#<host>:<port>/<my_account_name>
Thanks in advance for any help, much appreciated :)
I am not familiar with MongoHQ in particular, but you should be able to put something in Boot like this:
MongoDB.defineDbAuth(
DefaultMongoIdentifier,
new Mongo(new ServerAddress("<host>", <port>)),
<my_account_name>,
<user>,
<pass>
)
Where the <*> variables are the particular part of the connection URI that were provided to you when you signed up for MongoHQ.