Skip to content

Commit

Permalink
Revert "Revert changes to lamba_alias and lambda_event - unable to te…
Browse files Browse the repository at this point in the history
…st properly"

This reverts commit 82e7bc3.
  • Loading branch information
tremble committed Aug 26, 2020
1 parent 82e7bc3 commit f5897b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
17 changes: 5 additions & 12 deletions plugins/modules/lambda_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,13 @@

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 @@ -163,28 +162,22 @@ class AWSConnection:
def __init__(self, ansible_obj, resources, boto3_=True):

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

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

resources.append('iam')

for resource in resources:
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)
self.resource_client[resource] = ansible_obj.client(resource)

# 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 (ClientError, ParamValidationError, MissingParametersError) as e:
ansible_obj.fail_json(msg="Unable to connect, authorize or access resource: {0}".format(e))
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
ansible_obj.fail_json_aws(e, msg='Failed to connect to AWS')

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

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 @@ -144,7 +143,7 @@ class AWSConnection:
def __init__(self, ansible_obj, resources, use_boto3=True):

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

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

for resource in resources:
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)
self.resource_client[resource] = ansible_obj.client(resource)

# 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 (ClientError, ParamValidationError, MissingParametersError) as e:
ansible_obj.fail_json(msg="Unable to connect, authorize or access resource: {0}".format(e))
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
ansible_obj.fail_json_aws(e, msg='Failed to connect to AWS')

# set account ID
try:
Expand Down

0 comments on commit f5897b4

Please sign in to comment.