
    Vhv(                         d Z dZdZddlZddlZ	 ddlZddlmZ ddl	m
Z
 ddlmZ d Zd	 Zed
k(  r e        yy# e$ r Y -w xY w)a	  
---
module: lambda_execute
version_added: 5.0.0
short_description: Execute an AWS Lambda function
description:
  - This module executes AWS Lambda functions, allowing synchronous and asynchronous
    invocation.
  - Prior to release 5.0.0 this module was called M(community.aws.execute_lambda).
    The usage did not change.
  - This module was originally added to C(community.aws) in release 1.0.0.
extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.boto3
author:
  - "Ryan Scott Brown (@ryansb) <ryansb@redhat.com>"
notes:
  - Async invocation will always return an empty RV(result.output)  key.
  - Synchronous invocation may result in a function timeout, resulting in an
    empty RV(result.output) key.
options:
  name:
    description:
      - The name of the function to be invoked. This can only be used for
        invocations within the calling account. To invoke a function in another
        account, use O(function_arn) to specify the full ARN.
    type: str
  function_arn:
    description:
      - The name of the function to be invoked
    type: str
  tail_log:
    description:
      - If O(tail_log=true), the result of the task will include the last 4 KB
        of the CloudWatch log for the function execution. Log tailing only
        works if you use synchronous invocation O(wait=true). This is usually
        used for development or testing Lambdas.
    type: bool
    default: false
  wait:
    description:
      - Whether to wait for the function results or not. If O(wait=no)
        the task will not return any results. To wait for the Lambda function
        to complete, set O(wait=true) and the result will be available in the
        I(output) key.
    type: bool
    default: true
  dry_run:
    description:
      - Do not *actually* invoke the function. A C(DryRun) call will check that
        the caller has permissions to call the function, especially for
        checking cross-account permissions.
    type: bool
    default: false
  version_qualifier:
    description:
      - Which version/alias of the function to run. This defaults to the
        V(LATEST) revision, but can be set to any existing version or alias.
        See U(https://docs.aws.amazon.com/lambda/latest/dg/versioning-aliases.html)
        for details.
    type: str
  payload:
    description:
      - A dictionary in any form to be provided as input to the Lambda function.
    default: {}
    type: dict
a  
- amazon.aws.lambda_execute:
    name: test-function
    # the payload is automatically serialized and sent to the function
    payload:
      foo: bar
      value: 8
  register: response

# Test that you have sufficient permissions to execute a Lambda function in
# another account
- amazon.aws.lambda_execute:
    function_arn: arn:aws:lambda:us-east-1:123456789012:function/some-function
    dry_run: true

- amazon.aws.lambda_execute:
    name: test-function
    payload:
      foo: bar
      value: 8
    wait: true
    tail_log: true
  register: response
  # the response will have a `logs` key that will contain a log (up to 4KB) of the function execution in Lambda

# Pass the Lambda event payload as a json file.
- amazon.aws.lambda_execute:
    name: test-function
    payload: "{{ lookup('file','lambda_event.json') }}"
  register: response

- amazon.aws.lambda_execute:
    name: test-function
    version_qualifier: PRODUCTION
a  
result:
    description: Resulting data structure from a successful task execution.
    returned: success
    type: dict
    contains:
        output:
            description: Function output if O(wait=true) and the function returns a value.
            returned: success
            type: dict
            sample: "{ 'output': 'something' }"
        logs:
            description: The last 4KB of the function logs. Only provided if O(tail_log=true).
            type: str
            returned: if O(tail_log=true)
        status:
            description: V(StatusCode) of API call exit (200 for synchronous invokes, 202 for async).
            type: int
            sample: 200
            returned: always
    N)is_boto3_error_code)AnsibleAWSModule)AWSRetryc                  	   t        t               t               t        dd      t        dd      t        dd      t               t        i d            } t        | dddggd	g
      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }	 |j	                  dt        j                               }	i }|rd|d<   nd|d<   |s|j                  rd|d<   |r|rd|d<   n|r|s|j                  d       nd|d<   |r||d<   |rt        j                  |      |d<   |r||d<   n|r||d<   |j                  r|j!                  d       	 t#        	||xs |        |	j$                  d7i |d di}d&d'   d&d(}|j                  d)      r)	 t+        j,                  |j                  d)d&            |d*<   |d   dk(  r	 t        j0                  |d   j3                         j5                  d,            |d-<   t7        |j                  d-      t               rt9        |d-   j                  d/      |d-   j                  d0      g      r~d1}d2j;                  |j                  d-i       j                  d/g             |d-   j                  d0      |d-   j                  d3      d4}|j                   |j<                  d7i ||5       |j!                  d|6       y # t        j                  j                  t        j                  j                  f$ r}
|j                  |
d       Y d }
~
ud }
~
ww xY w# t'        d!      $ r}|j                  |d"       Y d }~d }~wt        j                  j                  $ r}|j                  |d#       Y d }~d }~wt        j                  j(                  $ r}|j                  |d$       Y d }~Xd }~wt        j                  j                  $ r}
|j                  |
d%       Y d }
~
d }
~
ww xY w# t.        $ r}
|j                  |
d+       Y d }
~
xd }
~
ww xY w# t.        $ r}
|j                  |
d.       Y d }
~
`d }
~
ww xY w)8NTbool)defaulttypeFdict)namefunction_arnwaittail_logdry_runversion_qualifierpayloadr   r   )r   r   )argument_specsupports_check_modemutually_exclusiverequired_one_ofr   r   r   r   r   lambda)retry_decoratorzFailed to connect to AWSmsgRequestResponseInvocationTypeEventDryRunTailLogTypezThe `tail_log` parameter is only available if the invocation waits for the function to complete. Set `wait` to true or turn off `tail_log`.None	QualifierPayloadFunctionName)changed	aws_retryResourceNotFoundExceptionzyCould not find Lambda to execute. Make sure the ARN is correct and your profile has permissions to execute this function.zGClient-side error when invoking Lambda, check inputs and specific errorz)Parameters to `invoke` failed to validatez1Unexpected failure while invoking Lambda function 
StatusCode)logsstatusoutput	LogResultr)   zFailed while decoding logsutf8r+   z+Failed while decoding function return value
stackTraceerrorMessagezwFunction executed, but there was an error in the Lambda function. Message: {errmsg}, Type: {type}, Stack Trace: {trace}
	errorType)traceerrmsgr	   )r   result)r$   r4    )r
   r   paramsgetclientr   jittered_backoffbotocore
exceptionsClientErrorBotoCoreErrorfail_json_aws
check_mode	fail_jsonjsondumps	exit_jsonwait_for_lambdainvoker   ParamValidationErrorbase64	b64decode	Exceptionloadsreaddecode
isinstanceanyjoinformat)r   moduler   r   await_returnr   r   r   r   r8   einvoke_paramsresponsenfeceveresultstemplate
error_datas                      m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/amazon/aws/plugins/modules/lambda_execute.pymainr]      s   VV$V,e&1U0&Rf-M # ^$
 22F ==V$D==$$^4L==$$V,Lmm	*G}}  ,H))*=>mm	*G@x9R9R9TU M*;&' +2&'&##*2&'L#)i 	,= 	 	
 $*i %6k"#'::g#6i (4n%	(,n%&Y(<= 6==A=ADA$ <(G ||K 	F$..x||K/LMGFO %&*;;	W $

8I+>+C+C+E+L+LV+T UGH gkk(+T2sX""<0'(2C2G2G2WX8
H  7;;x#<#@#@r#RS!(+//?)--k:	J !>:!>wO
T'2E ++X-@-@-N-NO @Q$>??@Z :; 
8 	 	
 	
 ** pR%noo33 RR%PQQ,, YQ$WXXY  	F  (D EE	F  	W  (U VV	Ws   (%M2 $'O
 &(R$ 8S 27O)OO
R!O11 R!P** R!
Q## R!RR!$	S-SS	S5S00S5c                    	 | j                  d      }| j                  d      }|j                  |       |j                  |       y # t        j                  j                  $ r}|j                  |d       Y d }~y d }~wt        j                  j                  t        j                  j                  f$ r}|j                  |d       Y d }~y d }~ww xY w)Nfunction_activefunction_updated)r#   z,Timeout while waiting on lambda to be Activer   z+Failed while waiting on lambda to be Active)
get_waiterr   r:   r;   WaiterErrorr>   r<   r=   )r8   rQ   name_or_arnclient_active_waiterclient_updated_waiterrS   s         r\   rD   rD     s    S%001BC & 1 12D E!!{!;"""<** TQ$RSS++X-@-@-N-NO SQ$QRRSs$   AA	 	C&A>>:C8CC__main__)DOCUMENTATIONEXAMPLESRETURNrG   rA   r:   ImportError<ansible_collections.amazon.aws.plugins.module_utils.botocorer   ;ansible_collections.amazon.aws.plugins.module_utils.modulesr   ;ansible_collections.amazon.aws.plugins.module_utils.retriesr   r]   rD   __name__r5       r\   <module>rp      so   CJ"H
,  	 ] X P3D	S zF m  		s   : AA