Skip to content

Commit

Permalink
Enable use AWS profiles other than default (#1248)
Browse files Browse the repository at this point in the history
* Use AWS_PROFILE with fallback to AWS_DEFAULT_PROFILE env variables
when reading ~/.aws/credentials file; use "default" when not set.

Signed-off-by: Nik Krumm <nkrumm@gmail.com>

* Add documentation.

Signed-off-by: Nik Krumm <nkrumm@gmail.com>
  • Loading branch information
nkrumm authored and pditommaso committed Aug 24, 2019
1 parent 9bbbe2d commit d743477
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/awscloud.rst
Expand Up @@ -38,6 +38,9 @@ Nextflow will use the AWS credentials defined in your environment, using the sta
* ``AWS_SECRET_ACCESS_KEY``
* ``AWS_DEFAULT_REGION``

If ``AWS_ACCESS_KEY_ID`` and ``AWS_SECRET_ACCESS_KEY`` are not defined in the environment, Nextflow will attempt to
retrieve credentials from your ``~/.aws/credentials`` or ``~/.aws/config`` files. The ``default`` profile can be
overridden via the environmental variable ``AWS_PROFILE`` (or ``AWS_DEFAULT_PROFILE``).

Alternatively AWS credentials can be specified in the Nextflow configuration file.
See :ref:`AWS configuration<config-aws>` for more details.
Expand Down
5 changes: 3 additions & 2 deletions modules/nf-commons/src/main/nextflow/Global.groovy
Expand Up @@ -101,8 +101,9 @@ class Global {

for( Path it : files ) {
final conf = new IniFile(it)
if( (a=conf.section('default').aws_access_key_id) && (b=conf.section('default').aws_secret_access_key) ) {
log.debug "Using AWS credential defined in `default` section in file: ${conf.file}"
final profile = env.get('AWS_PROFILE', env.get('AWS_DEFAULT_PROFILE', 'default'))
if( (a=conf.section(profile).aws_access_key_id) && (b=conf.section(profile).aws_secret_access_key) ) {
log.debug "Using AWS credential defined in `${profile}` section in file: ${conf.file}"
return [a,b]
}
}
Expand Down

0 comments on commit d743477

Please sign in to comment.