How should I set up my settings.py file for Django on EC2 Elastic Beanstalk to use a Postgres RDS ?
These docs only give the settings.py for MySQL.
You will probably just need to change the engine setting in your databases object. you will need to install psycopg2 to your environment. Here is what mine looks like. just fill in your db's info.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
Use psycopg2, and use environment variables (made available for you within Elastic Beanstalk):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
You'll need to include psycopg2 in a pip requirements.txt file (made using pip freeze > requirements.txt) and likely also install a Postgres dependency, postgresql-devel, by including the following in an .ebextensions/package.config file (the filename doesn't have to be packages.config, that's just what I use):
packages:
yum:
postgresql-devel: []
Related
I'm trying to deploy my express server on Heroku which needs to connect to the remote MySQL database.
I used 'heroku config:add DATABASE_URL=mysql://dbusername:dbpassword#databasehostIP:databaseserverport/databasename with the correct information but still it tries to connect through wrong address.
I also used 'heroku config:add EXTERNAL_DATABASE_URL=mysql://dbusername:dbpassword#databasehostIP:databaseserverport/databasename with the correct information but still it tries to connect through wrong address.
In my Heroku app panel under 'setting' in 'Config Vars' section I see that DATABASE_URL and EXTERNAL_DATABASE_URL appeared with correct information. but in heroku log I still see the wrong information
This is my sequelize variable on the express server:
const sequelize = new Sequelize('dbName', 'USER', 'Password', {
host:"hostAddress",
dialect: 'mysql'
}
But I see the following on Heroku log:
2019-02-16T18:31:42.231390+00:00 app[web.1]: Unhandled rejection
SequelizeAccessDeniedError: Access denied for user
'USER'#'ec2-54-162-8-141.compute-1.amazonaws.com' (using
password: YES)
How can I change 'ec2-54-162-8-141.compute-1.amazonaws.com' to the remote MySQL host address?
Try setting your variable with something like this:
if (process.env.DATABASE_URL) {
const sequelize = new Sequelize(process.env.DATABASE_URL, {
define: {
freezeTableName: true, // don't make plural table names
underscored: true // don't use camel case
},
dialect: 'mysql',
dialectOptions: {
ssl: true
},
logging: true,
protocol: 'mysql',
quoteIdentifiers: false // set case-insensitive
});
} else {
console.log('Fatal error: DATABASE_URL not set');
process.exit(1);
}
I'm trying to set up a chef recipe for automatic deployment of my app over ssl with tomcat chef cookbook.
It works fine without ssl, but when I try to set the attributes for ssl support I'm getting error:
undefined method `truststore_password' for Custom resource tomcat_instance from cookbook tomcat.
My role:
name "myapp"
override_attributes ({
"java" => {
"jdk_version"=> "6"
},
"oracle" => {
"accept_oracle_download_terms" => true
},
"tomcat" => {
"base_version" => 7,
"java_options" => "${JAVA_OPTS} -Xmx128M -Djava.awt.headless=true",
"secure" => true,
"client_auth" => true,
"scheme" => "https",
"ssl_enabled_protocols" => "TLSv1",
"keystore_password" => "mypass",
"truststore_password" => "mypass",
"ciphers" => "SSL_RSA_WITH_RC4_128_SHA",
"keystore_file" => "/etc/tomcat7/client.jks",
"truststore_file" => "/etc/tomcat7/cert.jks"
}
})
run_list "recipe[java]", "recipe[tomcat]"
Maybe I'm missing something, because I can't find any good tutorials on how to do this I'm also using chef-solo with vagrant.
If you look at the Tomcat cookbook documentation, you will see the following regarding the truststore_password attribute:
node['tomcat']['truststore_password'] - Generated by the secure_password method from the
openssl cookbook; if you are using Chef Solo,
set this attribute on the node
Perhaps this means that you can not set the attribute in your role definition whilst using Chef Solo, and you have to manually add it to the node attributes JSON file.
I have Vagrant set up and it's using Puppet as the provisioner with Puppet scripts setting up MySQL, PHP, etc. but the Puppet scripts have the hard coded values for passwords, addresses, etc.
I'd like to pull those out and store them in a external file alongside the Vagrantfile (not nested in the Puppet folder).
I thought this is what Hiera was for but cannot make sense of the documentation when trying to solve my problem. Any sugggestions?
I find that this worked example is a pretty good primer on how to use Hiera with Puppet for node specific configuration.
The above example basically has you go from a sites.pp file that looks like:
node "kermit.example.com" {
class { "ntp":
servers => [ '0.us.pool.ntp.org iburst','1.us.pool.ntp.org iburst','2.us.pool.ntp.org iburst','3.us.pool.ntp.org iburst'],
autoupdate => false,
restrict => [],
enable => true,
}
}
node "grover.example.com" {
class { "ntp":
servers => [ 'kermit.example.com','0.us.pool.ntp.org iburst','1.us.pool.ntp.org iburst','2.us.pool.ntp.org iburst'],
autoupdate => true,
restrict => [],
enable => true,
}
}
node "snuffie.example.com", "bigbird.example.com", "hooper.example.com" {
class { "ntp":
servers => [ 'grover.example.com', 'kermit.example.com'],
autoupdate => true,
enable => true,
}
}
To one that simply defines a list of nodes:
hiera_include('classes')
node "kermit.example.com", "grover.example.com", "snuffie.example.com", "bigbird.example.com", "hooper.example.com"
The config is then inherited depending on the hierarchy defined in hiera.yaml. In their example they simply use this:
---
:backends:
- yaml
:yaml:
:datadir: /etc/puppet/hieradata
:hierarchy:
- "node/%{::fqdn}"
- common
Which says to load any YAML config files under /etc/puppet/hieradata/node/%{::fqdn}.yaml (for example, /etc/puppet/hieradata/node/kermit.example.com.yaml) and where needed config options aren't found in this first step then to pull any remaining config data in from /etc/puppet/hieradata/common.yaml.
The YAML files themselves are then defined like:
kermit.example.com.yaml:
---
classes: ntp
ntp::restrict:
-
ntp::autoupdate: false
ntp::enable: true
ntp::servers:
- 0.us.pool.ntp.org iburst
- 1.us.pool.ntp.org iburst
- 2.us.pool.ntp.org iburst
- 3.us.pool.ntp.org iburst
common.yaml:
---
classes: ntp
ntp::autoupdate: true
ntp::enable: true
ntp::servers:
- grover.example.com iburst
- kermit.example.com iburst
Amazon's documentation provides examples in Java, .NET, and PHP of how to use DynamoDB Local. How do you do the same thing with the AWS Ruby SDK?
My guess is that you pass in some parameters during initialization, but I can't figure out what they are.
dynamo_db = AWS::DynamoDB.new(
:access_key_id => '...',
:secret_access_key => '...')
Are you using v1 or v2 of the SDK? You'll need to find that out; from the short snippet above, it looks like v2. I've included both answers, just in case.
v1 answer:
AWS.config(use_ssl: false, dynamo_db: { api_verison: '2012-08-10', endpoint: 'localhost', port: '8080' })
dynamo_db = AWS::DynamoDB::Client.new
v2 answer:
require 'aws-sdk-core'
dynamo_db = Aws::DynamoDB::Client.new(endpoint: 'http://localhost:8080')
Change the port number as needed of course.
Now aws-sdk version 2.7 throws an error as Aws::Errors::MissingCredentialsError: unable to sign request without credentials set when keys are absent. So below code works for me
dynamo_db = Aws::DynamoDB::Client.new(
region: "your-region",
access_key_id: "anykey-or-xxx",
secret_access_key: "anykey-or-xxx",
endpoint: "http://localhost:8080"
)
I've written a simple gist that shows how to start, create, update and query a local dynamodb instance.
https://gist.github.com/SundeepK/4ffff773f92e3a430481
Heres a run down of some simple code:
Below is a simple command to run dynamoDb in memory
#Assuming you have downloading dynamoDBLocal and extracted into a dir called dynamodbLocal
java -Djava.library.path=./dynamodbLocal/DynamoDBLocal_lib -jar ./dynamodbLocal/DynamoDBLocal.jar -inMemory -port 9010
Below is a simple ruby script
require 'aws-sdk-core'
dynamo_db = Aws::DynamoDB::Client.new(region: "eu-west-1", endpoint: 'http://localhost:9010')
dynamo_db.create_table({
table_name: 'TestDB',
attribute_definitions: [{
attribute_name: 'SomeKey',
attribute_type: 'S'
},
{
attribute_name: 'epochMillis',
attribute_type: 'N'
}
],
key_schema: [{
attribute_name: 'SomeKey',
key_type: 'HASH'
},
{
attribute_name: 'epochMillis',
key_type: 'RANGE'
}
],
provisioned_throughput: {
read_capacity_units: 5,
write_capacity_units: 5
}
})
dynamo_db.put_item( table_name: "TestDB",
item: {
"SomeKey" => "somevalue1",
"epochMillis" => 1
})
puts dynamo_db.get_item({
table_name: "TestDB",
key: {
"SomeKey" => "somevalue",
"epochMillis" => 1
}}).item
The above will create a table with a range key and also add/query for the same data that was added. Not you must already have version 2 of the aws gem installed.
I am developing puppet manifests for provisioning a VM through Vagrant. I am also new to puppet. While trying to use puppetlabs/apt module, I am encountering problems:
# manifests/default.pp (with commented lines removed)
import "stdlib"
import "apt"
class { 'apt':
always_apt_update => false,
disable_keys => undef,
proxy_host => false,
proxy_port => '8080',
purge_sources_list => false,
purge_sources_list_d => false,
purge_preferences_d => false
}
apt::release { "sid":}
This is the error message:
Puppet::Parser::AST::Resource failed with error ArgumentError:
Invalid resource type apt::release at /tmp/vagrant-puppet/manifests/default.pp:18
on node vmas1.dokeda.lt
I have been reading puppet docs; however, it hasn't helped. Could someone explain to me how to properly use this module?
I think the README incorrectly implies that apt::release is a define or type, when in fact the source code shows it's a class.
Instead, try calling it like this:
class { 'apt::release':
release_id => 'sid',
}
Also be sure not to use "import" but instead use "include".
Import is deprecated in more recent versions of puppet.