Skip to content

Commit 8ea3c6f

Browse files
committed
incorporating upstream changes
1 parent 74d31b4 commit 8ea3c6f

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

aws_lambda/aws_lambda.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def cleanup_old_versions(
5959

6060
client = get_client(
6161
'lambda', profile_name, aws_access_key_id, aws_secret_access_key,
62-
cfg.get('region'),
62+
cfg.get('region'), cfg
6363
)
6464

6565
response = client.list_versions_by_function(
@@ -465,19 +465,19 @@ def get_role_name(region, account_id, role):
465465

466466
def get_account_id(
467467
profile_name, aws_access_key_id, aws_secret_access_key,
468-
region=None,
468+
region=None, config=None
469469
):
470470
"""Query STS for a users' account_id"""
471471
client = get_client(
472472
'sts', profile_name, aws_access_key_id, aws_secret_access_key,
473-
region,
473+
region
474474
)
475475
return client.get_caller_identity().get('Account')
476476

477477

478478
def get_client(
479479
client, profile_name, aws_access_key_id, aws_secret_access_key,
480-
region=None,
480+
region=None, config=None
481481
):
482482
"""Shortcut for getting an initialized instance of the boto3 client."""
483483

@@ -487,7 +487,12 @@ def get_client(
487487
aws_secret_access_key=aws_secret_access_key,
488488
region_name=region,
489489
)
490-
return boto3.client(client)
490+
client_args = dict()
491+
492+
if config is not None and is_local(config):
493+
client_args["endpoint_url"] = get_endpoint_url(config, client)
494+
495+
return boto3.client(client, **client_args)
491496

492497

493498
def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
@@ -501,17 +506,17 @@ def create_function(cfg, path_to_zip_file, use_s3=False, s3_file=None):
501506

502507
account_id = get_account_id(
503508
profile_name, aws_access_key_id, aws_secret_access_key, cfg.get(
504-
'region',
509+
'region', cfg
505510
),
506-
)
511+
) if not is_local(cfg) else '000000000000'
507512
role = get_role_name(
508513
cfg.get('region'), account_id,
509514
cfg.get('role', 'lambda_basic_execution'),
510515
)
511516

512517
client = get_client(
513518
'lambda', profile_name, aws_access_key_id, aws_secret_access_key,
514-
cfg.get('region'),
519+
cfg.get('region'), cfg
515520
)
516521

517522
# Do we prefer development variable over config?
@@ -594,17 +599,17 @@ def update_function(
594599

595600
account_id = get_account_id(
596601
profile_name, aws_access_key_id, aws_secret_access_key, cfg.get(
597-
'region',
602+
'region', cfg
598603
),
599-
)
604+
) if not is_local(cfg) else '000000000000'
600605
role = get_role_name(
601606
cfg.get('region'), account_id,
602607
cfg.get('role', 'lambda_basic_execution'),
603608
)
604609

605610
client = get_client(
606611
'lambda', profile_name, aws_access_key_id, aws_secret_access_key,
607-
cfg.get('region'),
612+
cfg.get('region'), cfg
608613
)
609614

610615
# Do we prefer development variable over config?
@@ -685,7 +690,7 @@ def upload_s3(cfg, path_to_zip_file, *use_s3):
685690
aws_secret_access_key = cfg.get('aws_secret_access_key')
686691
client = get_client(
687692
's3', profile_name, aws_access_key_id, aws_secret_access_key,
688-
cfg.get('region'),
693+
cfg.get('region'), cfg
689694
)
690695
byte_stream = b''
691696
with open(path_to_zip_file, mode='rb') as fh:
@@ -725,7 +730,7 @@ def get_function_config(cfg):
725730
aws_secret_access_key = cfg.get('aws_secret_access_key')
726731
client = get_client(
727732
'lambda', profile_name, aws_access_key_id, aws_secret_access_key,
728-
cfg.get('region'),
733+
cfg.get('region'), cfg
729734
)
730735

731736
try:
@@ -742,3 +747,20 @@ def read_cfg(path_to_config_file, profile_name):
742747
elif 'AWS_PROFILE' in os.environ:
743748
cfg['profile'] = os.environ['AWS_PROFILE']
744749
return cfg
750+
751+
752+
def is_local(config):
753+
if config.get('endpoint_url_lambda') is None or config.get('endpoint_url_s3') is None:
754+
return False
755+
return True
756+
757+
758+
def get_endpoint_url(config, client):
759+
if not is_local(config):
760+
return None
761+
if client is 'lambda':
762+
return config.get('endpoint_url_lambda')
763+
elif client is 's3':
764+
return config.get('endpoint_url_s3')
765+
else:
766+
return None

0 commit comments

Comments
 (0)