Reputation: 29
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
I'd really appreciate any help!
Upvotes: 1
Views: 3274
Reputation: 66
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
Upvotes: 1