Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS FileSystemCredentials is not a constructor

I'm trying to load a JSON config file to protect my AWS keys

a.FileSystemCredentials is not a constructor
at constructor.loadFromPath(aws - sdk.min.js: 46)

This error is preventing me from using AWS.config.loadFromPath('../../s3.config.json');

It works fine when i use the unprotected AWS.config.update([json]); where json is the actual jsonData

app.js:

AWS.config.loadFromPath('../../s3.config.json');
var hub = new AWS.S3({ params: {Bucket: 'mybucket'} });

s3.config.json

{ "accessKeyId": "keyid", "secretAccessKey": "secretkey", "region": "us-east-1" }

like image 824
Hard Spocker Avatar asked Mar 09 '18 01:03

Hard Spocker


2 Answers

I have the same issue. You are probably loading the aws js sdk for browser.

As you can see: https://sdk.amazonaws.com/builder/js/, AWS.FileSystemCredentials is not included, that is why FileSystemCredentials is not a constructor (to be more specific it is undefined). It looks like you can only use AWS.config.loadFromPath on server side (with something like node.js).

like image 128
XAM Avatar answered Sep 24 '22 16:09

XAM


Loading credentials from a JSON document is not supported in browser scripts.You have to create an identity pool and give permission for the required access

const AWS = require('aws-sdk')
AWS.config.update({region: 'us-east-1'});

AWS.config.credentials = new AWS.CognitoIdentityCredentials({IdentityPoolId: 'ur pool id'});
like image 26
Subrata Fouzdar Avatar answered Sep 21 '22 16:09

Subrata Fouzdar