"Connection refused" when creating Elastic Beanstalk environment - mysql

I'm following this tutorial to set up Laravel on an Elastic Beanstalk environment:
https://deliciousbrains.com/scaling-laravel-using-aws-elastic-beanstalk-part-3-setting-elastic-beanstalk/
I've gone through it twice on a completely fresh install of Laravel just to see if it works, and it worked both times.
Now, I've gone through it again, but this time on my main Laravel project. I've double checked everything in the tutorial, and I'm confident that I didn't miss anything.
However, when I create the environment using this command from the tutorial (with the values filled in of course):
eb create --vpc.id {VPCID} --vpc.elbpublic --vpc.elbsubnets {VPCELBSUBNETS} --vpc.ec2subnets {VPCEC2SUBNETS} --vpc.securitygroups {VPCSG}
I get the following output error:
Printing Status:
INFO: createEnvironment is starting.
INFO: Using elasticbeanstalk-us-east-1-487650495335 as Amazon S3 storage bucket for environment data.
INFO: Created security group named: sg-018fe470
INFO: Created load balancer named: awseb-e-7-AWSEBLoa-1M3V7HA824OQ0
INFO: Created security group named: sg-7489ec08
INFO: Environment health has transitioned to Pending. Initialization in progress (running for 19 seconds). There are no instances.
INFO: Created Auto Scaling launch configuration named: awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingLaunchConfiguration-RZPSBCGFS6HY
INFO: Added instance [i-09cc6faf451ef3670] to your environment.
INFO: Created Auto Scaling group named: awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingGroup-BQI6UG2OLL7E
INFO: Waiting for EC2 instances to launch. This may take a few minutes.
INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:457680865345:scalingPolicy:a3629314-6d24-4871-a0a1-59d74a1087c2:autoScalingGroupName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingGroup-BQI6UG2OLL7E:policyName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingScaleDownPolicy-1SM372VEND7T6
INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:457680865345:scalingPolicy:b03a08fb-e39f-4dc5-8e00-f81f8059fc56:autoScalingGroupName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingGroup-BQI6UG2OLL7E:policyName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingScaleUpPolicy-AS65NNA5M4PP
INFO: Created CloudWatch alarm named: awseb-e-7xdtjzn4bn-stack-AWSEBCloudwatchAlarmLow-1D9SO13U3HBR0
INFO: Created CloudWatch alarm named: awseb-e-7xdtjzn4bn-stack-AWSEBCloudwatchAlarmHigh-1FUCKP1GWED3A
ERROR: [Instance: i-09cc6faf451ef3670] Command failed on instance. Return code: 1 Output: (TRUNCATED)...
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
Script php artisan optimize handling the post-install-cmd event returned with error code 1.
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_composer_install.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
ERROR: Create environment operation is complete, but with errors. For more information, see troubleshooting documentation.
As you can see, it says SQLSTATE[HY000] [2002] Connection refused when running php artisan optimize in the post-install-cmd.
If I try to connect to my MySQL RDS database on the command line, it connects successfully, so it doesn't look like connecting is the problem.
It took me a while to find what it meant by post-install-cmd, but I found it in my composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.3.*",
"doctrine/dbal": "^2.5",
"embed/embed": "^2.7",
"pda/pheanstalk": "~3.0",
"guzzlehttp/guzzle": "^6.2",
"intervention/image": "^2.3",
"approached/laravel-image-optimizer": "2.3.0",
"php-ffmpeg/php-ffmpeg": "0.9.3",
"laravelcollective/html": "^5.3",
"tymon/jwt-auth": "0.5.*",
"brozot/laravel-fcm": "^1.2",
"league/flysystem": "^1.0",
"cybercog/laravel-ban": "^2.1",
"pragmarx/firewall": "^1.0",
"predis/predis": "^1.1",
"aws/aws-sdk-php": "^3.31",
"dusterio/laravel-aws-worker": "^0.1.9",
"fideloper/proxy": "^3.3",
"aws/aws-sdk-php-laravel": "^3.1",
"league/flysystem-aws-s3-v3": "^1.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.0",
"symfony/css-selector": "3.1.*",
"symfony/dom-crawler": "3.1.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
To me, it doesn't look like anything is out of place.
What could the problem be?
Update
I just tried copying and pasting the contents of my project's composer.json to the fresh install of Laravel, and it successfully created an Elastic Beanstalk environment, so it looks like my composer.json isn't the problem.
What could it be?
Update #2
Looking at the eb logs, I discovered this:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `categories` where exists (select * from `topics` where `topics`.`category_id` = `categories`.`id`) order by `name` asc)
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [2002] Connection refused
The only place that this query is called is in my AppServiceProvider.php class. So I removed it, along with everything else that I added to the class, but I'm still getting the exact same error above, even though I removed that query call.
Why?

To answer my own question, the code in my AppServiceProvider.php file (within the boot() method) was causing it to fail.
What I did was wrapped all the code in the boot() method with this:
public function boot()
{
if (!$this->app->runningInConsole())
{
// Code here
}
}

Related

Node.js GraphQL API Stops working as soon as I deploy it: "Error validating datasource `db`: the URL must start with the protocol `mysql://"

I build a GraphQL API with Apollo and Prisma ORM which is connected to my hosted MySQL Database (The Database has already content in it).
When I run it on my localhost everything works fine and I can query the Database with GraphQL statements.
As soon as I deploy my node.js project to DigitalOcean (auto deployed with GitHub) it stops working and I get the following error:
{
"errors": [
{
"message": "\nInvalid `prisma.content.findMany()` invocation in\n/workspace/src/schema.js:36:29\n\n 33 const resolvers = {\n 34 Query: {\n 35 memes: (parent, args) => {\n→ 36 return prisma.content.findMany(\n error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.\n --> schema.prisma:7\n | \n 6 | provider = \"mysql\"\n 7 | url = env(\"DATABASE_URL\")\n | \n\nValidation Error Count: 1",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"memes"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"clientVersion": "3.6.0",
"stacktrace": [
"Error: ",
"Invalid `prisma.content.findMany()` invocation in",
"/workspace/src/schema.js:36:29",
"",
" 33 const resolvers = {",
" 34 Query: {",
" 35 memes: (parent, args) => {",
"→ 36 return prisma.content.findMany(",
" error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.",
" --> schema.prisma:7",
" | ",
" 6 | provider = \"mysql\"",
" 7 | url = env(\"DATABASE_URL\")",
" | ",
"",
"Validation Error Count: 1",
" at cb (/workspace/node_modules/#prisma/client/runtime/index.js:38689:17)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
}
}
],
"data": null
}
Here is my schema.prisma file:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
...
The only thing that is different from the hosted project compared to the local project is that I put .env file and node_modules on the .gitignore file.
So it seems like the project is accessing the wrong DATABASE_URL, but how should the hosted project know the DATABASE_URL in my .env file when the .env file is on .gitignore?
Here is what I do:
Change the DATABASE_URL in my .env file to my local MySQL Database hosted on a docker container
Run npx prisma migrate dev --preview-feature to generate the migration files
Run git add .
Run git commit -m "New Commit"
Run DATABASE_URL=mysql://censored:censored#censored:3306/censored npx prisma migrate resolve --applied "my_migration_folder_name" --preview-feature which succeeds and tells me "Migration my_migration_folder_name marked as applied."
Run git push
I can see that the Migration is successfully created on my MySQL Database but as soon as I run the app and try to query the database it gives me that error.
The code has to be correct because it is working on my localhost even when querying the hosted MySQL Database.
I also double checked that the Model in the schema.prisma file is in sync with my hosted MySQL Database schema.
I'm running out of ideas on what I could try.
EDIT
I actually think it has something to do with the environment variables I set in the settings of my DigitalOcean application.
Before it was set to:
envs:
- key: DATABASE_URL
scope: RUN_AND_BUILD_TIME
value: ${db.DATABASE_URL}
Now I set it to:
envs:
- key: DATABASE_URL
scope: RUN_AND_BUILD_TIME
value: mysql://censored:cesnored#censored:3306/censored
I thought that this will fix the problem but now it tells me that the connection fails because of wrong database credentials even though it is the right link with the right credentials.
I fixed it by clicking "Force rebuild and deploy" on my digitalOcean app.

using PKG with featherjs app

Has anyone ever tried using pkg with featherjs before? I'm having trouble getting it to work.
I get the following error when running my executable:
WARNING: No configurations found in configuration directory:/../project/config
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
pkg/prelude/bootstrap.js:1172
throw error;
^
TypeError: root path required
at Function.serveStatic [as static] (/snapshot/../project/node_modules/serve-static/index.js:40:11)
Not sure where to go from here if anyone has any guidance.
"bin": "src/index.js",
"scripts": {
"test": "npm run eslint && npm run mocha",
"dev": "./node_modules/nodemon/bin/nodemon.js src/",
"eslint": "eslint src/. test/. --config .eslintrc.json",
"mocha": "mocha test/ --recursive --exit",
"start": "node src/",
"pkg": "pkg . -t node9-macos-x64 --out-path pkg"
},
"pkg": {
"assets": [
"src/**/*",
"public/**/*",
"config/**/*",
"node_modules/config/**/*.*"
],
"scripts": [
"src/**/*.js",
"config/**/*.json"
]
},
The error is coming from node-config used by #feathersjs/configuration which trying to load config/default.json from the folder of the running application, not the the bundled package. You can either try building with the NODE_CONFIG environment variable set to the content of config/defualt.json or remove app.configure(configuration()) and app.set the configuration options your application needs, for example by requiring config/default.json (which should also work in theh packaged environment):
const config = require('../config/default.json');
Object.keys(config).forEach(key => {
app.set(key, config[key]);
});

How do I run a Postman collection subfolder with Newman

Postman: 5.5.0
Newman: 3.9.0
OS: Windows 10
How am I supposed to use the --folder command in Newman?
I have a Postman Collection Export (v2.1) which I am loading into Newman using:
- newman run "AME.postman_collection.json"
When I run this command, all tests execute as expected (including all sub folders.
However, I would like to run a specific subfolder called "Media". My understanding is that I should run the commandline:
- newman run "AME.postman_collection.json" --folder "Media"
Unfortunately this does not work. Newman simply reports no failure, but also 0 tests. I have also tried numerous other variations of the --folder parameter such as:
- "AME.Media"
- "AME/Media"
- "AME\Media"
- "\Media"
- "/Media"
- "Media/"
- "Media\"
- ".Media"
- And many, many more
Sample data from the Export below:
{
"info": {
"name": "AME",
"_postman_id": "023f6868-4c80-8c0f-01b6-78943caa38a6",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Media",
"description": "",
"item": [
{
"name": "showRenderer",
"event": [
Try updgrading to v3.9.1 (December 8, 2017).
The changelog states
Fixed folder option handling
that there was in error in folder handling which is now fixed. I tried v3.9.1 with sub folder and it worked for me.

Cannot create JHipster application (error in ng plugin)

I appreciate this is probably not a JHipster specific issue, but how some of my dependencies may be installed. It happens on 3.0.0 and 3.1.0. On the other hand 2.27.0 is fine.
This happens when I run yo jhipster.
...
Server app generated successfully.
Client app generated successfully.
(node:38364) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
[21:00:11] Using gulpfile ~/dev/projects/blog/gulpfile.js
[21:00:11] Starting 'install'...
[21:00:11] Starting 'wiredep:test'...
[21:00:11] Starting 'wiredep:app'...
[21:00:11] Starting 'ngconstant:dev'...
[21:00:11] 'ngconstant:dev' errored after 12 ms
[21:00:11] Error in plugin 'gulp-tslint-log'
TypeError: Path must be a string. Received null
at assertPath (path.js:7:11)
at Object.dirname (path.js:1324:5)
at getFilePath (/Users/me/dev/projects/blog/node_modules/gulp-ng-constant-fork/index.js:95:27)
at DestroyableTransform.objectStream [as _transform] (/Users/alberto/dev/projects/blog/node_modules/gulp-ng-constant-fork/index.js:60:25)
at DestroyableTransform.Transform._read (/Users/alberto/dev/projects/blog/node_modules/gulp-ng-constant-fork/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (/Users/alberto/dev/projects/blog/node_modules/gulp-ng-constant-fork/node_modules/readable-stream/lib/_stream_transform.js:172:12)
at doWrite (/Users/alberto/dev/projects/blog/node_modules/gulp-ng-constant-fork/node_modules/readable-stream/lib/_stream_writable.js:237:10)
at writeOrBuffer (/Users/alberto/dev/projects/blog/node_modules/gulp-ng-constant-fork/node_modules/readable-stream/lib/_stream_writable.js:227:5)
at DestroyableTransform.Writable.write (/Users/alberto/dev/projects/blog/node_modules/gulp-ng-constant-fork/node_modules/readable-stream/lib/_stream_writable.js:194:11)
at DestroyableTransform.Writable.end (/Users/alberto/dev/projects/blog/node_modules/gulp-ng-constant-fork/node_modules/readable-stream/lib/_stream_writable.js:352:10)
at ngConstantPlugin (/Users/alberto/dev/projects/blog/node_modules/gulp-ng-constant-fork/index.js:33:16)
at Gulp.<anonymous> (/Users/alberto/dev/projects/blog/gulpfile.js:164:12)
at module.exports (/Users/alberto/dev/projects/blog/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/Users/alberto/dev/projects/blog/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/Users/alberto/dev/projects/blog/node_modules/orchestrator/index.js:214:10)
at Gulp.Orchestrator.start (/Users/alberto/dev/projects/blog/node_modules/orchestrator/index.js:134:8)
Then when I start the application I get this on the browser's console:
Uncaught Error: [$injector:modulerr] Failed to instantiate module blogApp due to:
Error: [$injector:nomod] Module 'blogApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.5.2/$injector/nomod?p0=badgeritoApp
at http://127.0.0.1:8080/bower_components/angular/angular.js:68:12
at http://127.0.0.1:8080/bower_components/angular/angular.js:2034:17
at ensure (http://127.0.0.1:8080/bower_components/angular/angular.js:1958:38)
at module (http://127.0.0.1:8080/bower_components/angular/angular.js:2032:14)
at http://127.0.0.1:8080/bower_components/angular/angular.js:4524:22
at forEach (http://127.0.0.1:8080/bower_components/angular/angular.js:321:20)
at loadModules (http://127.0.0.1:8080/bower_components/angular/angular.js:4508:5)
at createInjector (http://127.0.0.1:8080/bower_components/angular/angular.js:4430:19)
at doBootstrap (http://127.0.0.1:8080/bower_components/angular/angular.js:1710:20)
at bootstrap (http://127.0.0.1:8080/bower_components/angular/angular.js:1731:12)
Here is the content of .yo-rc.json
{
"generator-jhipster": {
"jhipsterVersion": "3.0.0",
"baseName": "blog",
"packageName": "com.albertofaci.blog",
"packageFolder": "com/albertofaci/blog",
"serverPort": "8080",
"authenticationType": "session",
"hibernateCache": "no",
"clusteredHttpSession": "no",
"websocket": "no",
"databaseType": "mongodb",
"devDatabaseType": "mongodb",
"prodDatabaseType": "mongodb",
"searchEngine": "no",
"buildTool": "gradle",
"enableSocialSignIn": false,
"rememberMeKey": "94cf21b11aff8d8d4a9b9b3724834876b995e5b1",
"useSass": false,
"applicationType": "monolith",
"testFrameworks": [
"gatling"
],
"enableTranslation": true,
"nativeLanguage": "en",
"languages": [
"en",
"es"
]
}}
node version: v6.0.0
npm version: 3.8.7
java 8
Any hints or ideas?
I had exactly the same problem as the OP, I changed to use the LTS version of Node as Gaël Marziou suggested. This fixed the problem.

rabbitmq 3.3.4 shovel configuration is crashing start process

I'm trying to configure the shovel plugin via the config file (running in docker) but I get this error:
BOOT FAILED
===========
Error description:
{error,{failed_to_cluster_with,[rabbit#dalmacpmfd57],
"Mnesia could not connect to any nodes."}}
The config is set up this way because the destination for shovel will be created on demand when a dev environment is spun up... the source is a permanent rabbitmq instance running that the new, dev environment will attach to.
Here is the config file contents:
[
{rabbitmq_shovel,
[{shovels,
[{indexer_replica_static,
[{sources,
[{broker, [ "amqp://guest:guest#rabbitmq/newdev" ]},
{declarations,
[{'queue.declare', [{queue, <<"Indexer_Replica_Static">>}, durable]},
{'queue.bind',[ {exchange, <<"Indexer">>}, {queue, <<"Indexer_Replica_Static">>}]}
]
}
]
},
{destinations,
[{broker, "amqp://"},
{declarations, [ {'exchange.declare', [ {exchange, <<"Indexer_Replica_Static">>}
, {type, <<"fanout">>}, durable]},
{'queue.declare', [
{queue, <<"Indexer_Replica_Static">>},
durable]},
{'queue.bind',
[ {exchange, <<"Indexer_Replica_Static">>}
, {queue, <<"Indexer_Replica_Static">>}
]}
]
}
]
},
{queue, <<"Indexer_Replica_Static">>},
{prefetch_count, 0},
{ack_mode, on_confirm},
{publish_properties, [ {delivery_mode, 2} ]},
{reconnect_delay, 2.5}
]
}
]
},
{reconnect_delay, 2.5}
]
}
].
[UPDATE]
This is being run in docker but since I couldn't debug the issue in docker I tried booting up rabbit locally with the same config file. I noticed in the logs that the rabbit config system variable I set (RABBITMQ_CONFIG_FILE) isn't reflected in the log and the shovel settings haven't been applied (no surprise huh). I verified the variable with an echo statement and the correct path is displayed: /dev/rabbitmq_server-3.3.4/rabbitmq
=INFO REPORT==== 3-Sep-2014::15:30:37 ===
node : rabbit#dalmacpmfd57
home dir : /Users/e002678
config file(s) : (none)
cookie hash : n6vhh8tY7Z+uR2DV6gcHUg==
log : /usr/local/rabbitmq_server-3.3.4/sbin/../var/log/rabbitmq/rabbit#dalmacpmfd57.log
sasl log : /usr/local/rabbitmq_server-3.3.4/sbin/../var/log/rabbitmq/rabbit#dalmacpmfd57- sasl.log
database dir : /usr/local/rabbitmq_server-3.3.4/sbin/../var/lib/rabbitmq/mnesia/rabbit#dalmacpmfd57
Thanks!