Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Load config from ~/.aws/config

change log says Load config from ~/.aws/config if AWS_SDK_LOAD_CONFIG is set. Couldn't find any examples or documentation regarding how to load the config. Any help!

like image 946
sreenivas Avatar asked Jun 08 '17 10:06

sreenivas


People also ask

How do I access AWS config?

Sign in to the AWS Management Console and open the AWS Config console at https://console.aws.amazon.com/config/ .

How do I deploy AWS config?

To deploy a configuration by using the consoleIn the navigation pane, choose AWS AppConfig. On the Applications tab, choose an application, and then choose View details. On the Environments tab, choose an environment, and then choose View details. Choose Start deployment.

Where is my AWS config file?

The config file is located at ~/. aws/config on Linux or macOS, or at C:\Users\ USERNAME \. aws\config on Windows. This file contains the configuration settings for the default profile and any named profiles.

How do I enable AWS config recording?

To turn on AWS Config with the AWS CLI, use the put-configuration-recorder, put-delivery-channel, and start-configuration-recorder commands. The put-configuration-recorder command creates a new configuration recorder to record your selected resource configurations.


2 Answers

The answer of sreenivas is correct. It also seems to be the only way to do this without writing a custom function.

I've traced it back in the source code and the the way it loads ~/.aws/config is similar to this pseudocode:

if process.env.AWS_SDK_LOAD_CONFIG:
  return load('~/.aws/credentials').overwrite('~/.aws/config')
else:
  return load('~/.aws/credentials')

This also means you can set the environment variable after require('aws-sdk'), as long as you do it before new SharedIniFileCredentials({..}) or credentials.refresh(). Beware that credentials.get() will not work until the sessiontoken has expired.

like image 24
Toon Vanvreckem Avatar answered Oct 05 '22 18:10

Toon Vanvreckem


There is a little bit of magic in how aws-sdk loads the config

either set the env variable

export AWS_SDK_LOAD_CONFIG="true"

or before loading the aws-sdk set

process.env.AWS_SDK_LOAD_CONFIG = true; 

Then load the aws module;

var AWS = require('aws-sdk');

You can access the region directly by

AWS.config.region
like image 60
sreenivas Avatar answered Oct 05 '22 18:10

sreenivas