Setting AWS SDK credentials in Node - javascript

I am having trouble setting the aws credentials for a react app that needs the aws sdk. I have set up my credentials file in the '~/.aws/credentials' path, and I know this is okay. However, I don't know how to go about this in my jsx file. My understanding was that the SDK checks this credentials file on its own.
Here is my code:
process.env.AWS_SDK_LOAD_CONFIG = true;
var AWS = require("aws-sdk");
console.log(AWS.config)
But when I log the AWS.config object, I see credentials: null, region: null
Image of console log
I'd really appreciate any help!

Are you sure everything is fine with your .aws/config and .aws/credentials files?
I've run your code and I got below result. Please note I don't have the config file so region is undefined.
Config {
credentials:
SharedIniFileCredentials {
expired: false,
expireTime: null,
accessKeyId: 'xxx',
sessionToken: undefined,
filename: '/home/juzeff/.aws/credentials',
profile: 'default',
disableAssumeRole: true },
credentialProvider:
CredentialProviderChain {
providers: [ [Function], [Function], [Function], [Function] ] },
region: undefined,
If you load the credentials with AWS_SDK_LOAD_CONFIG make sure you have the [default] profile specified in your credentials file. If you have multiple profiles load the one you want to use this way:
const profile = 'corporate-bucket';
const credentials = new AWS.SharedIniFileCredentials({ profile });
AWS.config.credentials = credentials;
assuming your .aws/credentials file looks like this:
[corporate-bucket]
aws_access_key_id = xxx
aws_secret_access_key = yyy

Related

Common config for both Firebase and Google Cloud function

For a project, I am trying to deploy Google Cloud functions as well as Firebase Cloud functions from the same file. That is, I have initiated a Firebase project and in that project file I'm trying to deploy a Google Cloud function for the same project.
The problem I'm facing is that the config for G Cloud function is to be hardcoded in the code itself because unlike Firebase Cloud functions, it is unable to get it from functions.config(). Is there a way in which we can get the config for both the platforms using a single method? Or an alternative way so that for G Cloud functions we don't have to hard code the config again and again?
an example of what hard coded config means is as follows.
For establishing connection to mysql-
function getMySQLConfig() {
if (!mysqlConfig) {
// const config = functions.config();
//const connectionName = config.config_server_sql.connectionName;//
mysqlConfig = {
// config we get from functions.config()
// host: config.config_server_sql.ip,
// port: config.config_server_sql.port,
// user: config.config_server_sql.dbUser,
// password: config.config_server_sql.password,
// database: config.config_server_sql.dbName,
// multipleStatements: true,
// charset: "utf8mb4_unicode_ci",
//hard coded config
dbName: "config_db",
ip: ‘IP_ADDRESS,
dbUser: "root",
port: 3306,
connectionName: ‘SAMPLE_NAME’,
password: ‘PASSWORD’,
...configSetting
};
// mysqlConfig.socketPath = `/cloudsql/${connectionName}`;
}
return mysqlConfig;
}

API Keys with dotenv made me net::ERR_CONNECTION_REFUSED

Im trying so hard to run this "job project" from Github, so i put my API keys on .env created file locate on root of api directory
APP_ID=00000000
API_KEY=000000000000000000000000
...and put this code on my config.js :
require('dotenv').config({ path: 'api/.env' })
module.exports = {
APP_ID: process.env.APP_ID,
API_KEY: process.env.API_KEY,
BASE_URL: 'https://api.adzuna.com/v1/api/jobs',
BASE_PARAMS: 'search/1?&results_per_page=20&content-
type=application/json',
};
But it looks like the request failing with this error net::ERR_CONNECTION_REFUSED:
I think, it dosent happens to take the api keys values, because accessKeyId is always empty
So, does there any other way to hide the api keys for it to work ?
Thanks

Is aws-amplify with auth broken?

I am trying to build a react app which will use the aws hosted ui for authentication. I am trying to use aws-amplify to achieve this, and so far I am having no such luck.
Here the docs state that the auth config should look like this.
const oauth = {
domain : 'your-domain-prefix.auth.us-east-1.amazoncognito.com',
scope : ['phone', 'email', 'profile', 'openid','aws.cognito.signin.user.admin'],
redirectSignIn : 'http://www.example.com/signin/',
redirectSignOut : 'http://www.example.com/signout/',
responseType: 'code',
}
But when I use this config setup I get the following error.
The parameters: App client Id, App web domain, the redirect URL when
you are signed in and the redirect URL when you are signed out are
required.
As you can see, those params are clearly supplied. So I clicked on the source map file linked in my console with the error message, and saw this.
if (data == null || !ClientId || !AppWebDomain || !RedirectUriSignIn || !RedirectUriSignOut) {
throw new Error(this.getCognitoConstants().PARAMETERERROR);
}
Which makes it seem more like the config should look a little something like this.
const auth = {
AppWebDomain: "aaaaa",
TokenScopesArray: ["phone", "email", "profile", "openid", "aws.cognito.signin.user.admin"],
RedirectUriSignIn: "http://localhost:3000",
RedirectUriSignOut: "http://localhost:3000",
responseType: "token",
ClientId: "aaa",
UserPoolId: "aaa",
};
But when doing this, and trying to send the user to the hosted ui as the docs say here I get this error.
Uncaught TypeError: Cannot read property 'domain' of undefined
Once again I looked at the source and found this.
var domain = config.domain,
Which makes it seem like its expecting the config which does not work.
At this point I am really lost and can use any help at all.
Going through the Auth.ts code, it appears that you have to include the userPoolId and userPoolWebClientId fields, in addition to oauth. Here's how I got it to work:
const oauth = {
domain: 'XXXXXX.auth.us-west-2.amazoncognito.com',
scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
redirectSignIn: 'http://localhost:3000/',
redirectSignOut: 'http://localhost:3000/',
responseType: 'code'
};
Auth.configure({
oauth: oauth,
region: 'us-west-2',
userPoolId: 'us-west-2_XXXXXXXXX',
userPoolWebClientId: 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
});

Meteor-Up (mup) error after "mup init"

I am trying to use mup to deploy a meteor app to my DigitalOcean droplet.
What I have done so far
Followed instructions on "Meteor-Up" website http://meteor-up.com/getting-started.html.
Installed mup via "npm install --global mup"
Created ".deploy" folder in my app directory. Ran "mup init".
Configured file "mup.js" file for my app, ran "mup setup".
Here is where I ran into an error. Upon running "mup setup", I am hit with the following error. [
What I tried:
I suspected that there could have been an issue with my syntax when configuring the mup.js file. After double-checking and not finding any error, I decided to re-install mup, and try running "mup setup" without modifying the "mup.js" file. However, I still receive the same error message.
Furthermore, after running "mup init", I can no longer run "mup" either, as I receive the same error as seen above. I suspect therefore that the issue is with the mup.js file. I have attached the generic version provided by meteor-up below (which still causes the error seen above).
module.exports = {
servers: {
one: {
// TODO: set host address, username, and authentication method
host: '1.2.3.4',
username: 'root',
// pem: './path/to/pem'
// password: 'server-password'
// or neither for authenticate from ssh-agent
}
},
app: {
// TODO: change app name and path
name: 'app',
path: '../app',
servers: {
one: {},
},
buildOptions: {
serverOnly: true,
},
env: {
// TODO: Change to your app's url
// If you are using ssl, it needs to start with https://
ROOT_URL: 'http://app.com',
MONGO_URL: 'mongodb://localhost/meteor',
},
// ssl: { // (optional)
// // Enables let's encrypt (optional)
// autogenerate: {
// email: 'email.address#domain.com',
// // comma separated list of domains
// domains: 'website.com,www.website.com'
// }
// },
docker: {
// change to 'abernix/meteord:base' if your app is using Meteor 1.4 - 1.5
image: 'abernix/meteord:node-8.4.0-base',
},
// Show progress bar while uploading bundle to server
// You might need to disable it on CI servers
enableUploadProgressBar: true
},
mongo: {
version: '3.4.1',
servers: {
one: {}
}
}
};
Any help would be greatly appreciated!
Thank you
The error dialog you posted shows a syntax error at line 10, character 5.
If you take a look:
module.exports = {
servers: {
one: {
// TODO: set host address, username, and authentication method
host: '1.2.3.4',
username: 'root',
// pem: './path/to/pem'
// password: 'server-password'
// or neither for authenticate from ssh-agent
}
^^^ This character
},
It's a closing brace which JS was not expecting. So why was it unexpected, lets move back to the last valid syntax:
module.exports = {
servers: {
one: {
// TODO: set host address, username, and authentication method
host: '1.2.3.4',
username: 'root',
^^^ This character
// pem: './path/to/pem'
// password: 'server-password'
// or neither for authenticate from ssh-agent
}
},
Well, looks like a comma which isn't followed by another key-value pair. Also known as a syntax error.
Take the comma out and things should be fine again!
I faced this same issue today. The problem is that Windows is trying to execute the mup.js file as a JScript script.
Here is the solution from the Meteor Up Common Problems page:
Mup silently fails, mup.js file opens instead, or you get a Windows script error
If you are using Windows, make sure you run commands with mup.cmd instead of mup , or use PowerShell.
That is, instead of mup setup, run mup.cmd setup.

Angular 5 externalize prod passwords

I have prod and dev environments. Prod env is using user credentials to log in (in the future there will be a technical user but for now we need to pass our credentials).
I want to be able to send the compiled file to my colleague but without my credentials. Instead of that I would like to have json file with credentials so each of us would have own file eg. in project root or on C:/.
Is there a simply way to externalize data like that? I want to only import the file instead of calling the http to fetch it.
export const environment = {
production: false,
url: '../assets/vdbs.json',
token: '',
};
I want the token to be placed in another file so I would end with
export const environment = {
production: false,
url: '../assets/vdbs.json',
};
and separate file eg.
token: sometoken,
anotherdata; somedata,
or
TOKEN = sometoken;
ANOTHER_DATA = somedata;

Categories