����JFIF��������� Mr.X
  
  __  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

deexcl@216.73.217.71: ~ $
# (c) 2016, Pierre Jodouin <pjodouin@virtualcomputing.solutions>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type


DOCUMENTATION = '''
---
module: lambda_event
version_added: 5.0.0
short_description: Creates, updates or deletes AWS Lambda function event mappings
description:
  - This module allows the management of AWS Lambda function event source mappings such as DynamoDB and Kinesis stream
    events via the Ansible framework. These event source mappings are relevant only in the AWS Lambda pull model, where
    AWS Lambda invokes the function.
    It is idempotent and supports "Check" mode.  Use module M(amazon.aws.lambda) to manage the lambda
    function itself and M(amazon.aws.lambda_alias) to manage function aliases.
  - This module was originally added to C(community.aws) in release 1.0.0.

author:
  - Pierre Jodouin (@pjodouin)
  - Ryan Brown (@ryansb)
options:
  lambda_function_arn:
    description:
      - The name or ARN of the lambda function.
    required: true
    aliases: ['function_name', 'function_arn']
    type: str
  state:
    description:
      - Describes the desired state.
    default: "present"
    choices: ["present", "absent"]
    type: str
  alias:
    description:
      - Name of the function alias.
      - Mutually exclusive with I(version).
    type: str
  version:
    description:
      - Version of the Lambda function.
      - Mutually exclusive with I(alias).
    type: int
    default: 0
  event_source:
    description:
      - Source of the event that triggers the lambda function.
      - For DynamoDB and Kinesis events, select C(stream)
      - For SQS queues, select C(sqs)
    default: stream
    choices: ['stream', 'sqs']
    type: str
  source_params:
    description:
      -  Sub-parameters required for event source.
    suboptions:
      source_arn:
        description:
          -  The Amazon Resource Name (ARN) of the SQS queue, Kinesis stream or DynamoDB stream that is the event source.
        type: str
        required: true
      enabled:
        description:
          -  Indicates whether AWS Lambda should begin polling or readin from the event source.
        default: true
        type: bool
      batch_size:
        description:
          -  The largest number of records that AWS Lambda will retrieve from your event source at the time of invoking your function.
        default: 100
        type: int
      starting_position:
        description:
          - The position in the stream where AWS Lambda should start reading.
          - Required when I(event_source=stream).
        choices: [TRIM_HORIZON,LATEST]
        type: str
      function_response_types:
        description:
          - (Streams and Amazon SQS) A list of current response type enums applied to the event source mapping.
        type: list
        elements: str
        choices: [ReportBatchItemFailures]
        version_added: 5.5.0
    required: true
    type: dict
extends_documentation_fragment:
  - amazon.aws.aws
  - amazon.aws.ec2
  - amazon.aws.boto3

'''

EXAMPLES = '''
# Example that creates a lambda event notification for a DynamoDB stream
- name: DynamoDB stream event mapping
  amazon.aws.lambda_event:
    state: present
    event_source: stream
    function_name: "{{ function_name }}"
    alias: Dev
    source_params:
      source_arn: arn:aws:dynamodb:us-east-1:123456789012:table/tableName/stream/2016-03-19T19:51:37.457
      enabled: True
      batch_size: 100
      starting_position: TRIM_HORIZON
  register: event

# Example that creates a lambda event notification for a DynamoDB stream
- name: DynamoDB stream event mapping
  amazon.aws.lambda_event:
    state: present
    event_source: stream
    function_name: "{{ function_name }}"
    source_params:
      source_arn: arn:aws:dynamodb:us-east-1:123456789012:table/tableName/stream/2016-03-19T19:51:37.457
      enabled: True
      batch_size: 100
      starting_position: LATEST
      function_response_types:
        - ReportBatchItemFailures
  register: event

- name: Show source event
  ansible.builtin.debug:
    var: event.lambda_stream_events
'''

RETURN = '''
---
lambda_stream_events:
    description: list of dictionaries returned by the API describing stream event mappings
    returned: success
    type: list
'''

import re

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

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

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 get_aws_connection_info


# ---------------------------------------------------------------------------------------------------
#
#   Helper Functions & classes
#
# ---------------------------------------------------------------------------------------------------


class AWSConnection:
    """
    Create the connection object and client objects as required.
    """

    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.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)

            # 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))

        # set account ID
        try:
            self.account_id = self.resource_client['iam'].get_user()['User']['Arn'].split(':')[4]
        except (ClientError, ValueError, KeyError, IndexError):
            self.account_id = ''

    def client(self, resource='lambda'):
        return self.resource_client[resource]


def pc(key):
    """
    Changes python key into Pascale case equivalent. For example, 'this_function_name' becomes 'ThisFunctionName'.

    :param key:
    :return:
    """

    return "".join([token.capitalize() for token in key.split('_')])


def ordered_obj(obj):
    """
    Order object for comparison purposes

    :param obj:
    :return:
    """

    if isinstance(obj, dict):
        return sorted((k, ordered_obj(v)) for k, v in obj.items())
    if isinstance(obj, list):
        return sorted(ordered_obj(x) for x in obj)
    else:
        return obj


def set_api_sub_params(params):
    """
    Sets module sub-parameters to those expected by the boto3 API.

    :param params:
    :return:
    """

    api_params = dict()

    for param in params.keys():
        param_value = params.get(param, None)
        if param_value:
            api_params[pc(param)] = param_value

    return api_params


def validate_params(module, aws):
    """
    Performs basic parameter validation.

    :param module:
    :param aws:
    :return:
    """

    function_name = module.params['lambda_function_arn']

    # validate function name
    if not re.search(r'^[\w\-:]+$', function_name):
        module.fail_json(
            msg='Function name {0} is invalid. Names must contain only alphanumeric characters and hyphens.'.format(function_name)
        )
    if len(function_name) > 64 and not function_name.startswith('arn:aws:lambda:'):
        module.fail_json(msg='Function name "{0}" exceeds 64 character limit'.format(function_name))

    elif len(function_name) > 140 and function_name.startswith('arn:aws:lambda:'):
        module.fail_json(msg='ARN "{0}" exceeds 140 character limit'.format(function_name))

    # check if 'function_name' needs to be expanded in full ARN format
    if not module.params['lambda_function_arn'].startswith('arn:aws:lambda:'):
        function_name = module.params['lambda_function_arn']
        module.params['lambda_function_arn'] = 'arn:aws:lambda:{0}:{1}:function:{2}'.format(aws.region, aws.account_id, function_name)

    qualifier = get_qualifier(module)
    if qualifier:
        function_arn = module.params['lambda_function_arn']
        module.params['lambda_function_arn'] = '{0}:{1}'.format(function_arn, qualifier)

    return


def get_qualifier(module):
    """
    Returns the function qualifier as a version or alias or None.

    :param module:
    :return:
    """

    qualifier = None
    if module.params['version'] > 0:
        qualifier = str(module.params['version'])
    elif module.params['alias']:
        qualifier = str(module.params['alias'])

    return qualifier


# ---------------------------------------------------------------------------------------------------
#
#   Lambda Event Handlers
#
#   This section defines a lambda_event_X function where X is an AWS service capable of initiating
#   the execution of a Lambda function (pull only).
#
# ---------------------------------------------------------------------------------------------------

def lambda_event_stream(module, aws):
    """
    Adds, updates or deletes lambda stream (DynamoDb, Kinesis) event notifications.
    :param module:
    :param aws:
    :return:
    """

    client = aws.client('lambda')
    facts = dict()
    changed = False
    current_state = 'absent'
    state = module.params['state']

    api_params = dict(FunctionName=module.params['lambda_function_arn'])

    # check if required sub-parameters are present and valid
    source_params = module.params['source_params']

    source_arn = source_params.get('source_arn')
    if source_arn:
        api_params.update(EventSourceArn=source_arn)
    else:
        module.fail_json(msg="Source parameter 'source_arn' is required for stream event notification.")

    # check if optional sub-parameters are valid, if present
    batch_size = source_params.get('batch_size')
    if batch_size:
        try:
            source_params['batch_size'] = int(batch_size)
        except ValueError:
            module.fail_json(msg="Source parameter 'batch_size' must be an integer, found: {0}".format(source_params['batch_size']))

    # optional boolean value needs special treatment as not present does not imply False
    source_param_enabled = module.boolean(source_params.get('enabled', 'True'))

    # check if event mapping exist
    try:
        facts = client.list_event_source_mappings(**api_params)['EventSourceMappings']
        if facts:
            current_state = 'present'
    except ClientError as e:
        module.fail_json(msg='Error retrieving stream event notification configuration: {0}'.format(e))

    if state == 'present':
        if current_state == 'absent':

            starting_position = source_params.get('starting_position')
            if starting_position:
                api_params.update(StartingPosition=starting_position)
            elif module.params.get('event_source') == 'sqs':
                # starting position is not required for SQS
                pass
            else:
                module.fail_json(msg="Source parameter 'starting_position' is required for stream event notification.")

            if source_arn:
                api_params.update(Enabled=source_param_enabled)
            if source_params.get('batch_size'):
                api_params.update(BatchSize=source_params.get('batch_size'))
            if source_params.get('function_response_types'):
                api_params.update(FunctionResponseTypes=source_params.get('function_response_types'))

            try:
                if not module.check_mode:
                    facts = client.create_event_source_mapping(**api_params)
                changed = True
            except (ClientError, ParamValidationError, MissingParametersError) as e:
                module.fail_json(msg='Error creating stream source event mapping: {0}'.format(e))

        else:
            # current_state is 'present'
            api_params = dict(FunctionName=module.params['lambda_function_arn'])
            current_mapping = facts[0]
            api_params.update(UUID=current_mapping['UUID'])
            mapping_changed = False

            # check if anything changed
            if source_params.get('batch_size') and source_params['batch_size'] != current_mapping['BatchSize']:
                api_params.update(BatchSize=source_params['batch_size'])
                mapping_changed = True

            if source_param_enabled is not None:
                if source_param_enabled:
                    if current_mapping['State'] not in ('Enabled', 'Enabling'):
                        api_params.update(Enabled=True)
                        mapping_changed = True
                else:
                    if current_mapping['State'] not in ('Disabled', 'Disabling'):
                        api_params.update(Enabled=False)
                        mapping_changed = True

            if mapping_changed:
                try:
                    if not module.check_mode:
                        facts = client.update_event_source_mapping(**api_params)
                    changed = True
                except (ClientError, ParamValidationError, MissingParametersError) as e:
                    module.fail_json(msg='Error updating stream source event mapping: {0}'.format(e))

    else:
        if current_state == 'present':
            # remove the stream event mapping
            api_params = dict(UUID=facts[0]['UUID'])

            try:
                if not module.check_mode:
                    facts = client.delete_event_source_mapping(**api_params)
                changed = True
            except (ClientError, ParamValidationError, MissingParametersError) as e:
                module.fail_json(msg='Error removing stream source event mapping: {0}'.format(e))

    return camel_dict_to_snake_dict(dict(changed=changed, events=facts))


def main():
    """Produce a list of function suffixes which handle lambda events."""
    source_choices = ["stream", "sqs"]

    argument_spec = dict(
        state=dict(required=False, default='present', choices=['present', 'absent']),
        lambda_function_arn=dict(required=True, aliases=['function_name', 'function_arn']),
        event_source=dict(required=False, default="stream", choices=source_choices),
        source_params=dict(type='dict', required=True),
        alias=dict(required=False, default=None),
        version=dict(type='int', required=False, default=0),
    )

    module = AnsibleAWSModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        mutually_exclusive=[['alias', 'version']],
        required_together=[],
    )

    aws = AWSConnection(module, ['lambda'])

    validate_params(module, aws)

    if module.params['event_source'].lower() in ('stream', 'sqs'):
        results = lambda_event_stream(module, aws)
    else:
        module.fail_json(msg='Please select `stream` or `sqs` as the event type')

    module.exit_json(**results)


if __name__ == '__main__':
    main()

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
autoscaling_group.py File 82.17 KB 0644
autoscaling_group_info.py File 16.46 KB 0644
aws_az_info.py File 6.12 KB 0644
aws_caller_info.py File 3.66 KB 0644
cloudformation.py File 35.27 KB 0644
cloudformation_info.py File 19.77 KB 0644
cloudtrail.py File 24 KB 0644
cloudtrail_info.py File 9.68 KB 0644
cloudwatch_metric_alarm.py File 18.87 KB 0644
cloudwatch_metric_alarm_info.py File 11.32 KB 0644
cloudwatchevent_rule.py File 18.49 KB 0644
cloudwatchlogs_log_group.py File 13.58 KB 0644
cloudwatchlogs_log_group_info.py File 4.72 KB 0644
cloudwatchlogs_log_group_metric_filter.py File 7.12 KB 0644
ec2_ami.py File 31.7 KB 0644
ec2_ami_info.py File 9.32 KB 0644
ec2_eip.py File 24.46 KB 0644
ec2_eip_info.py File 4.36 KB 0644
ec2_eni.py File 33.18 KB 0644
ec2_eni_info.py File 9.94 KB 0644
ec2_instance.py File 87.54 KB 0644
ec2_instance_info.py File 22.73 KB 0644
ec2_key.py File 12.67 KB 0644
ec2_metadata_facts.py File 29.53 KB 0644
ec2_security_group.py File 62.18 KB 0644
ec2_security_group_info.py File 10.7 KB 0644
ec2_snapshot.py File 13.31 KB 0644
ec2_snapshot_info.py File 10.67 KB 0644
ec2_spot_instance.py File 24.21 KB 0644
ec2_spot_instance_info.py File 10.6 KB 0644
ec2_tag.py File 4.97 KB 0644
ec2_tag_info.py File 1.78 KB 0644
ec2_vol.py File 31.01 KB 0644
ec2_vol_info.py File 6.89 KB 0644
ec2_vpc_dhcp_option.py File 21.87 KB 0644
ec2_vpc_dhcp_option_info.py File 7.19 KB 0644
ec2_vpc_endpoint.py File 18.54 KB 0644
ec2_vpc_endpoint_info.py File 9.74 KB 0644
ec2_vpc_endpoint_service_info.py File 5.61 KB 0644
ec2_vpc_igw.py File 8.65 KB 0644
ec2_vpc_igw_info.py File 6 KB 0644
ec2_vpc_nat_gateway.py File 31.08 KB 0644
ec2_vpc_nat_gateway_info.py File 7.28 KB 0644
ec2_vpc_net.py File 26.35 KB 0644
ec2_vpc_net_info.py File 10.16 KB 0644
ec2_vpc_route_table.py File 33.92 KB 0644
ec2_vpc_route_table_info.py File 8.92 KB 0644
ec2_vpc_subnet.py File 21.59 KB 0644
ec2_vpc_subnet_info.py File 7.1 KB 0644
elb_application_lb.py File 32.32 KB 0644
elb_application_lb_info.py File 13.22 KB 0644
elb_classic_lb.py File 78.43 KB 0644
iam_policy.py File 10.46 KB 0644
iam_policy_info.py File 5.9 KB 0644
iam_user.py File 21.6 KB 0644
iam_user_info.py File 5.96 KB 0644
kms_key.py File 38.2 KB 0644
kms_key_info.py File 18.46 KB 0644
lambda.py File 33.54 KB 0644
lambda_alias.py File 10.47 KB 0644
lambda_event.py File 15.42 KB 0644
lambda_execute.py File 10.08 KB 0644
lambda_info.py File 20.06 KB 0644
lambda_layer.py File 12.31 KB 0644
lambda_layer_info.py File 7.39 KB 0644
lambda_policy.py File 13.45 KB 0644
rds_cluster.py File 46.03 KB 0644
rds_cluster_info.py File 10.62 KB 0644
rds_cluster_snapshot.py File 12.69 KB 0644
rds_instance.py File 63.34 KB 0644
rds_instance_info.py File 12.63 KB 0644
rds_instance_snapshot.py File 12.26 KB 0644
rds_option_group.py File 23.86 KB 0644
rds_option_group_info.py File 12.56 KB 0644
rds_param_group.py File 13.04 KB 0644
rds_snapshot_info.py File 12.4 KB 0644
rds_subnet_group.py File 13.05 KB 0644
route53.py File 28.19 KB 0644
route53_health_check.py File 24.4 KB 0644
route53_info.py File 32.05 KB 0644
route53_zone.py File 19.93 KB 0644
s3_bucket.py File 52.93 KB 0644
s3_object.py File 55.57 KB 0644
s3_object_info.py File 32.55 KB 0644