Skip to content

Commit 9ba608c

Browse files
committed
Merge branch 'master' of github.com:nficano/python-lambda
* 'master' of github.com:nficano/python-lambda: modify the role ARN slightly if in govcloud. New GovCloud regions may be added, so included a constant map ARN_PREFIXES for future expansion
2 parents 8169e46 + 9d3942a commit 9ba608c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

aws_lambda/aws_lambda.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
from .helpers import timestamp
2525

2626

27+
ARN_PREFIXES = {
28+
'us-gov-west-1': 'aws-us-gov'
29+
}
30+
2731
log = logging.getLogger(__name__)
2832

2933

@@ -358,9 +362,10 @@ def pip_install_to_target(path, requirements=False, local_package=None):
358362
_install_packages(path, packages)
359363

360364

361-
def get_role_name(account_id, role):
365+
def get_role_name(region, account_id, role):
362366
"""Shortcut to insert the `account_id` and `role` into the iam string."""
363-
return 'arn:aws:iam::{0}:role/{1}'.format(account_id, role)
367+
prefix = ARN_PREFIXES.get(region, 'aws')
368+
return 'arn:{0}:iam::{1}:role/{2}'.format(prefix, account_id, role)
364369

365370

366371
def get_account_id(aws_access_key_id, aws_secret_access_key):
@@ -389,7 +394,7 @@ def create_function(cfg, path_to_zip_file):
389394
aws_secret_access_key = cfg.get('aws_secret_access_key')
390395

391396
account_id = get_account_id(aws_access_key_id, aws_secret_access_key)
392-
role = get_role_name(account_id, cfg.get('role', 'lambda_basic_execution'))
397+
role = get_role_name(cfg.get('region'), account_id, cfg.get('role', 'lambda_basic_execution'))
393398

394399
client = get_client(
395400
'lambda', aws_access_key_id, aws_secret_access_key,
@@ -436,7 +441,7 @@ def update_function(cfg, path_to_zip_file):
436441
aws_secret_access_key = cfg.get('aws_secret_access_key')
437442

438443
account_id = get_account_id(aws_access_key_id, aws_secret_access_key)
439-
role = get_role_name(account_id, cfg.get('role', 'lambda_basic_execution'))
444+
role = get_role_name(cfg.get('region'), account_id, cfg.get('role', 'lambda_basic_execution'))
440445

441446
client = get_client(
442447
'lambda', aws_access_key_id, aws_secret_access_key,

0 commit comments

Comments
 (0)