Skip to content

Commit

Permalink
Revert changes to lamba_alias and lambda_event - unable to test properly
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Aug 26, 2020
1 parent 769d701 commit 82e7bc3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
17 changes: 12 additions & 5 deletions plugins/modules/lambda_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,14 @@

try:
import boto3
import botocore
from botocore.exceptions import ClientError, ParamValidationError, MissingParametersError
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info


class AWSConnection:
Expand All @@ -162,22 +163,28 @@ class AWSConnection:
def __init__(self, ansible_obj, resources, boto3_=True):

try:
self.region = ansible_obj.region
self.region, self.endpoint, aws_connect_kwargs = get_aws_connection_info(ansible_obj, boto3=boto3_)

self.resource_client = dict()
if not resources:
resources = ['lambda']

resources.append('iam')

for resource in resources:
self.resource_client[resource] = ansible_obj.client(resource)
aws_connect_kwargs.update(dict(region=self.region,
endpoint=self.endpoint,
conn_type='client',
resource=resource
))
self.resource_client[resource] = boto3_conn(ansible_obj, **aws_connect_kwargs)

# if region is not provided, then get default profile/session region
if not self.region:
self.region = self.resource_client['lambda'].meta.region_name

except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
ansible_obj.fail_json_aws(e, msg='Failed to connect to AWS')
except (ClientError, ParamValidationError, MissingParametersError) as e:
ansible_obj.fail_json(msg="Unable to connect, authorize or access resource: {0}".format(e))

try:
self.account_id = self.resource_client['iam'].get_user()['User']['Arn'].split(':')[4]
Expand Down
16 changes: 11 additions & 5 deletions plugins/modules/lambda_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@

try:
import boto3
import botocore
from botocore.exceptions import ClientError, ParamValidationError, MissingParametersError
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info


# ---------------------------------------------------------------------------------------------------
Expand All @@ -143,7 +144,7 @@ class AWSConnection:
def __init__(self, ansible_obj, resources, use_boto3=True):

try:
self.region = ansible_obj.region
self.region, self.endpoint, aws_connect_kwargs = get_aws_connection_info(ansible_obj, boto3=use_boto3)

self.resource_client = dict()
if not resources:
Expand All @@ -152,14 +153,19 @@ def __init__(self, ansible_obj, resources, use_boto3=True):
resources.append('iam')

for resource in resources:
self.resource_client[resource] = ansible_obj.client(resource)
aws_connect_kwargs.update(dict(region=self.region,
endpoint=self.endpoint,
conn_type='client',
resource=resource
))
self.resource_client[resource] = boto3_conn(ansible_obj, **aws_connect_kwargs)

# if region is not provided, then get default profile/session region
if not self.region:
self.region = self.resource_client['lambda'].meta.region_name

except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
ansible_obj.fail_json_aws(e, msg='Failed to connect to AWS')
except (ClientError, ParamValidationError, MissingParametersError) as e:
ansible_obj.fail_json(msg="Unable to connect, authorize or access resource: {0}".format(e))

# set account ID
try:
Expand Down

0 comments on commit 82e7bc3

Please sign in to comment.