message: 'Missing credentials in config', inside initiateAuth(), Which credentials am I missing? - node.js

I'm trying to set up rudimentary functions for user authentication in my project, but when I ask for the auth token with aws-sdk function initiateAuth() it tells me that I'm missing credentials in my config object. I've managed to set up user creation and confirmation without any credentials. Whats more is that the documentation does not make it clear that initiateAuth() requires any credentials, or which credentials it wants.
When I ask for authentication, I get this error
{ Error: connect ENETUNREACH 169.254.169.254:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
message: 'Missing credentials in config',
errno: 'ENETUNREACH',
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2019-04-13T22:26:34.352Z,
originalError:
{ message: 'Could not load credentials from any providers',
errno: 'ENETUNREACH',
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2019-04-13T22:26:34.352Z,
originalError:
{ errno: 'ENETUNREACH',
code: 'ENETUNREACH',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
message: 'connect ENETUNREACH 169.254.169.254:80' } } }
my code is very simple
const http = require("http")
const aws = require('aws-sdk')
const JSON5 = require('json5')
const serviceProvider = aws.CognitoIdentityServiceProvider
aws.config.update({region : 'us-east-2'})
var service = new serviceProvider()
function authorizeUser(username, password){
service.initiateAuth({
AuthFlow: 'USER_PASSWORD_AUTH',
ClientId: 'placeholder',
AuthParameters: {
'USERNAME': username,
'PASSWORD': password
},
},
function(error, data){
if(error){
console.log(error)
}
else if(data){
console.log(data)
}
})
}
Why does this function seem to ask for credentials when it shouldn't need them? If it wants credentials, which ones does it need, and how do I provide them?
EDIT: This post solved my problem. I would still appreciate an answer as to why this works however.
all I did was change one line of code.
aws.config.update({region : 'us-east-2', accessKeyId: 'anything', secretAccessKey: 'anything'})
User Pools for Amazon Cognito - CredentialsError: Missing credentials in config

Related

Nodemailer error: Error: connect ECONNREFUSED 127.0.0.1:587 suddenly appears

So I´m currently updating my JS backend to TS.
The project was written back in 2018 or 2019 and had some outdated stuff going on.
But it actually worked all well.
Now, for some reason, nodemailer wont work anymore and throws this error:
Error: connect ECONNREFUSED 127.0.0.1:587
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) { errno: -61, code: 'ESOCKET', syscall: 'connect', address:
'127.0.0.1', port: 587, command: 'CONN' }
I know there have been posts on this topic, but I don´t think my configuration is wrong, because it worked before totally fine and I didn´t really change anything, except for adding some types.
// defining transport to connect to mail host
const transport = nodemailer.createTransport({
host: process.env.EMAIL_PROVIDER,
port: 587,
tls: {
ciphers: 'SSLv3',
rejectUnauthorized: false,
},
debug: true,
auth: {
user: process.env.EMAILADDRESS_SENDER,
pass: process.env.EMAILPASSWORD,
},
});
export const sendOrderCreatedEmail = async (customer: Customer, paymentId: string) => {
const mailOptions: MailOptions = {
from: process.env.EMAILADDRESS_SENDER!,
to: process.env.EMAILADDRESS_RECEIVER!,
subject: `new Audit ${paymentId}`,
html: ...,
};
await sendEmail(mailOptions);
};
const sendEmail = async (mailOptions: MailOptions) => {
// send email with defined transport
transport.sendMail(mailOptions).catch(err => {
console.log(err);
});
};
"nodemailer": "^6.7.5",
any idea what could be wrong there? Cheers!

Executing ksql query using node npm ksqlDb-client throwing an timeout error

Hi am trying to execute the KSQL query using npm package ksqlDb-client package, it throws an timeout error. I have attached the code as well, please let me know any issues over there.
when am hit this GET URL below method will execute https://localhost:5000/testKsql
exports.getKSQLStream = async () => {
const options = {
authorization: {
username: "admin",
password: "pw",
ssl: {
ca: CAs,
crt: myClientCert,
key: myClientKey,
}
},
host: 'https://ixxxx.xcxx.net',
timeout: 20000
}
const client = new KsqldbClient(options);
await client.connect();
const streamRes = await client.query('list streams;');
console.log("streams",streamRes);
await client.disconnect();
}
when I hit that URL from postman am getting below response in node console.
Error on Http2 client. Error: connect ETIMEDOUT 16.2XX.X4.xxx:8088
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '16.2XX.X4.xxx',
port: 8088
}
I faced recently with the same issue and found that library has bug with authorization. I pushed PR in repo, but you can patch your local copy in the same way.
https://github.com/Streaminy/ksqldb-client/pull/4

"EC2 Metadata roleName request returned error" using aws encryption library with NestJS

I am trying to use aws encryption sdk in a NestJS application, the next code source shows the implementation.
import { Controller, Get } from '#nestjs/common';
import {KmsKeyringNode, encrypt} from '#aws-crypto/client-node'
#Controller('encryption')
export class EncryptionController {
// constructor() {}
#Get()
async crypt() {
const generatorKeyId = "generatior key";
const masterKeyId = "master key id";
const keyring = new KmsKeyringNode({keyIds:[masterKeyId], generatorKeyId: generatorKeyId});
const plainText = "My passwords for senstive data";
const context = {
accountId: "100",
purpose: "youtube demo",
country: "Sri Lanka"
};
const { result } = await encrypt(keyring, plainText, { encryptionContext: context });
console.log(result)
}
}
but when I execute a request to see the result of my implementation I receive the next error
Error: connect EHOSTUNREACH 169.254.169.254:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14) {
message: 'Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1',
errno: 'EHOSTUNREACH',
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2020-06-09T11:41:47.638Z,
originalError: {
message: 'Could not load credentials from any providers',
errno: 'EHOSTUNREACH',
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2020-06-09T11:41:47.638Z,
originalError: {
message: 'EC2 Metadata roleName request returned error',
errno: 'EHOSTUNREACH',
code: 'EHOSTUNREACH',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2020-06-09T11:41:47.637Z,
originalError: [Object]
}
}
}
However I copy a nodejs script from this tutorial to see if it works with my aws sdk set up
and I did not receive any error, also if a execute aws kms encryption methods in the cli I hadn't any error.
I tried to export AWS_SDK_LOAD_CONFIG=1 variable how I saw in other similar errors.
Does anyone know what's going on?
I had the same problem. It cost me quite some head ache because I had this running in AWS Fargate and debugging is not that easy there.
The error means the Javascript SDK can not find the AWS credentials.
Here you can see in what order the SDK tries to load the credentials from:
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html
My error was quite embarrassing, I just had a typo in my environment variables. My variable was AWS_ACCESSS_KEY_ID instead of AWS_ACCESS_KEY_ID. (Quite hard to see the difference, right?)
So probably double check the names of your environment variables (or config files)

AWS SQS "ECONNREFUSED" when sending message

Trying to send Message to AWS SQS from nodejs. I keep getting this specific error
{ Error: connect ECONNREFUSED 127.0.0.1:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1161:14)
message: 'connect ECONNREFUSED 127.0.0.1:443',
errno: 'ECONNREFUSED',
code: 'NetworkingError',
syscall: 'connect',
address: '127.0.0.1',
port: 443,
region: 'us-east-1',
hostname: '',
retryable: true,
time: 2018-07-16T11:26:04.672Z }
I have set my credentials in my App, Given full access to my user for AWSSQSService. I can get all the details about the queue itself, queue names, etc. I just cannot send a message to the queue. My code below to send it
{
let AWS = require('aws-sdk');
AWS.config.update({region: constants.AWS.AWS_REGION});
let sqs = new AWS.SQS({apiVersion: '2012-11-05'});
let SQSQueueUrl = ' https://sqs.us-east-1.amazonaws.com/*queueName*';
let params = {
MessageBody: 'demo', /* required */
QueueUrl: SQSQueueUrl, /* required */
};
sqs.sendMessage(params, function(err, data) {
if(err)
console.log(err);
else
console.log(data);
});
}
So, I came across the same error, remove the space at the start of your SQSQueueUrl, it solves the error.
so go with
let SQSQueueUrl = 'https://sqs.us-east-1.amazonaws.com/queueName';
That comes up when you don't configure access key and secret; you can specify it either on line 2 with the config or via environment

Node mailer Error: connect ECONNREFUSED

I've tried all solutions that have been already posted on the site like
1)Declaring host as smtp.gmail.com
2)secure:false and rejectUnauthorized as unregistered
3) Allowing less secure apps permission in Gmail
Code snippet looks like this
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'gmail',
port:'465',
secure: 'false',
auth: {
user: 'my_id',
pass: 'my_password'
},
tls: {
rejectUnauthorized: false
}
});
var mailOptions = {
from: 'myemail',
to: receiver's email,
subject: "some text",
text: "some text"
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
and i still get the error
{ Error: connect ECONNREFUSED 74.125.124.109:465
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
code: 'ECONNECTION',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '74.125.124.109',
port: 465,
command: 'CONN' }
Any thoughts on how to solve this?
It is very possible, especially if you're on Windows, that you have an antivirus, antimalware, or firewall that is blocking the requests. Windows Firewall in particular is aggressive about blocking SMTP out from unregistered programs.

Resources