o ckF[*T@sXddlZddlmZddlmZddlmZddlmZddl m Z GdddeZ dS) N)json)JSONResponseError)AWSAuthConnection) RegionInfo) exceptionscseZdZdZdZdZdZeZe j e j e j e j dZfddZdd Z d$d d Zd dZddZddZddZddZ d%ddZd$ddZddZ d&ddZ d'dd Z ! d(d"d#ZZS))AWSLambdaConnectionaM AWS Lambda **Overview** This is the AWS Lambda API Reference. The AWS Lambda Developer Guide provides additional information. For the service overview, go to `What is AWS Lambda`_, and for information about how the service works, go to `AWS LambdaL How it Works`_ in the AWS Lambda Developer Guide. z 2014-11-11z us-east-1zlambda.us-east-1.amazonaws.com)InvalidRequestContentExceptionResourceNotFoundExceptionInvalidParameterValueExceptionServiceExceptionc sP|d}|st||j|j}n|d=|j|d<tt|jdi|||_dS)Nregionhost) getrDefaultRegionNameDefaultRegionEndpointendpointsuperr__init__r )selfkwargsr  __class__r7/usr/lib/python3/dist-packages/boto/awslambda/layer1.pyr7s   zAWSLambdaConnection.__init__cCsdgS)Nzhmac-v4r)rrrr_required_auth_capabilityBsz-AWSLambdaConnection._required_auth_capabilityNc CsTd}|||d}i}i} |dur||d<|dur||d<|jd|dt||| dS) a Identifies an Amazon Kinesis stream as the event source for an AWS Lambda function. AWS Lambda invokes the specified function when records are posted to the stream. This is the pull model, where AWS Lambda invokes the function. For more information, go to `AWS LambdaL How it Works`_ in the AWS Lambda Developer Guide. This association between an Amazon Kinesis stream and an AWS Lambda function is called the event source mapping. You provide the configuration information (for example, which stream to read from and which AWS Lambda function to invoke) for the event source mapping in the request body. This operation requires permission for the `iam:PassRole` action for the IAM role. It also requires permission for the `lambda:AddEventSource` action. :type event_source: string :param event_source: The Amazon Resource Name (ARN) of the Amazon Kinesis stream that is the event source. Any record added to this stream causes AWS Lambda to invoke your Lambda function. AWS Lambda POSTs the Amazon Kinesis event, containing records, to your Lambda function as JSON. :type function_name: string :param function_name: The Lambda function to invoke when AWS Lambda detects an event on the stream. :type role: string :param role: The ARN of the IAM role (invocation role) that AWS Lambda can assume to read from the stream and invoke the function. :type batch_size: integer :param batch_size: The largest number of records that AWS Lambda will give to your function in a single event. The default is 100 records. :type parameters: map :param parameters: A map (key-value pairs) defining the configuration for AWS Lambda to use when reading the event source. Currently, AWS Lambda supports only the `InitialPositionInStream` key. The valid values are: "TRIM_HORIZON" and "LATEST". The default value is "TRIM_HORIZON". For more information, go to `ShardIteratorType`_ in the Amazon Kinesis Service API Reference. "/2014-11-13/event-source-mappings/) EventSource FunctionNameRoleN BatchSize ParametersPOSTexpected_statusdataheadersparams make_requestrdumps) r event_source function_namerole batch_size parametersurir'r& query_paramsrrradd_event_sourceEs3  z$AWSLambdaConnection.add_event_sourcecCd|}|jd|ddS)a Deletes the specified Lambda function code and configuration. This operation requires permission for the `lambda:DeleteFunction` action. :type function_name: string :param function_name: The Lambda function to delete. /2014-11-13/functions/{0}DELETEr$formatr)rr,r0rrrdelete_functions z#AWSLambdaConnection.delete_functioncCr3)a> Returns configuration information for the specified event source mapping (see AddEventSource). This operation requires permission for the `lambda:GetEventSource` action. :type uuid: string :param uuid: The AWS Lambda assigned ID of the event source mapping. %/2014-11-13/event-source-mappings/{0}GETr"r7r8ruuidr0rrrget_event_sources z$AWSLambdaConnection.get_event_sourcecCr3)a: Returns the configuration information of the Lambda function and a presigned URL link to the .zip file you uploaded with UploadFunction so you can download the .zip file. Note that the URL is valid for up to 10 minutes. The configuration information is the same information you provided as parameters when uploading the function. This operation requires permission for the `lambda:GetFunction` action. :type function_name: string :param function_name: The Lambda function name. r4r=r"r7r8r:rrr get_functions z AWSLambdaConnection.get_functioncCr3)a Returns the configuration information of the Lambda function. This the same information you provided as parameters when uploading the function by using UploadFunction. This operation requires permission for the `lambda:GetFunctionConfiguration` operation. :type function_name: string :param function_name: The name of the Lambda function for which you want to retrieve the configuration information. '/2014-11-13/functions/{0}/configurationr=r"r7r8r:rrrget_function_configurations z.AWSLambdaConnection.get_function_configurationc Csd|}i}i}ztt|}Wn*ttfy;z|Wntttfy.tdwtt | j }Ynw||d<|j d|d|||dS)aF Submits an invocation request to AWS Lambda. Upon receiving the request, Lambda executes the specified function asynchronously. To see the logs generated by the Lambda function execution, see the CloudWatch logs console. This operation requires permission for the `lambda:InvokeAsync` action. :type function_name: string :param function_name: The Lambda function name. :type invoke_args: blob :param invoke_args: JSON that you want to provide to your Lambda function as input. z'/2014-11-13/functions/{0}/invoke-async/zFFile-like object passed to parameter ``invoke_args`` must be seekable.Content-Lengthr!r# r9strlen TypeErrorAttributeErrortellOSErrorIOErrorosfstatfilenost_sizer))rr, invoke_argsr0r&r1content_lengthrrr invoke_asyncs(   z AWSLambdaConnection.invoke_asyncc Csld}i}i}i}|dur||d<|dur||d<|dur ||d<|dur(||d<|jd|dt|||d S) a Returns a list of event source mappings. For each mapping, the API returns configuration information (see AddEventSource). You can optionally specify filters to retrieve specific event source mappings. This operation requires permission for the `lambda:ListEventSources` action. :type event_source_arn: string :param event_source_arn: The Amazon Resource Name (ARN) of the Amazon Kinesis stream. :type function_name: string :param function_name: The name of the AWS Lambda function. :type marker: string :param marker: Optional string. An opaque pagination token returned from a previous `ListEventSources` operation. If present, specifies to continue the list from where the returning call left off. :type max_items: integer :param max_items: Optional integer. Specifies the maximum number of event sources to return in response. This value must be greater than 0. rNrrMarkerMaxItemsr=r"r#r() revent_source_arnr,marker max_itemsr0r'r&r1rrrlist_event_sourcess   z&AWSLambdaConnection.list_event_sourcescCsLd}i}i}i}|dur||d<|dur||d<|jd|dt|||dS)a Returns a list of your Lambda functions. For each function, the response includes the function configuration information. You must use GetFunction to retrieve the code for your function. This operation requires permission for the `lambda:ListFunctions` action. :type marker: string :param marker: Optional string. An opaque pagination token returned from a previous `ListFunctions` operation. If present, indicates where to continue the listing. :type max_items: integer :param max_items: Optional integer. Specifies the maximum number of AWS Lambda functions to return in response. This parameter value must be greater than 0. z/2014-11-13/functions/NrUrVr=r"r#r()rrXrYr0r'r&r1rrrlist_functions"s  z"AWSLambdaConnection.list_functionscCr3)aN Removes an event source mapping. This means AWS Lambda will no longer invoke the function for events in the associated source. This operation requires permission for the `lambda:RemoveEventSource` action. :type uuid: string :param uuid: The event source mapping ID. r<r5r6r7r8r>rrrremove_event_sourceDs z'AWSLambdaConnection.remove_event_sourcec Csd|}i}i} i} |dur|| d<|dur|| d<|dur#|| d<|dur+|| d<|dur3|| d<|jd|d t|| | d S) a Updates the configuration parameters for the specified Lambda function by using the values provided in the request. You provide only the parameters you want to change. This operation must only be used on an existing Lambda function and cannot be used to update the function's code. This operation requires permission for the `lambda:UpdateFunctionConfiguration` action. :type function_name: string :param function_name: The name of the Lambda function. :type role: string :param role: The Amazon Resource Name (ARN) of the IAM role that Lambda will assume when it executes your function. :type handler: string :param handler: The function that Lambda calls to begin executing your function. For Node.js, it is the module-name.export value in your function. :type description: string :param description: A short user-defined function description. Lambda does not use this value. Assign a meaningful description as you see fit. :type timeout: integer :param timeout: The function execution time at which Lambda should terminate the function. Because the execution time has cost implications, we recommend you set this value based on your expected execution time. The default is 3 seconds. :type memory_size: integer :param memory_size: The amount of memory, in MB, your Lambda function is given. Lambda uses this memory size to infer the amount of CPU allocated to your function. Your function use-case determines your CPU and memory requirements. For example, a database operation might need less memory compared to an image processing function. The default value is 128 MB. The value must be a multiple of 64 MB. rBNrHandler DescriptionTimeout MemorySizePUTr"r#)r9r)rr*) rr,r-handler descriptiontimeout memory_sizer0r'r&r1rrrupdate_function_configurationUs$ .  z1AWSLambdaConnection.update_function_configurationc  Csd|} i} i} |dur|| d<|dur|| d<|dur!|| d<|dur)|| d<|dur1|| d<|dur9|| d<| durA| | d <ztt|} Wn*ttfysz|Wntttfyftd wtt | j } Ynw| | d <|j d | d || | dS)a Creates a new Lambda function or updates an existing function. The function metadata is created from the request parameters, and the code for the function is provided by a .zip file in the request body. If the function name already exists, the existing Lambda function is updated with the new code and metadata. This operation requires permission for the `lambda:UploadFunction` action. :type function_name: string :param function_name: The name you want to assign to the function you are uploading. The function names appear in the console and are returned in the ListFunctions API. Function names are used to specify functions to other AWS Lambda APIs, such as InvokeAsync. :type function_zip: blob :param function_zip: A .zip file containing your packaged source code. For more information about creating a .zip file, go to `AWS LambdaL How it Works`_ in the AWS Lambda Developer Guide. :type runtime: string :param runtime: The runtime environment for the Lambda function you are uploading. Currently, Lambda supports only "nodejs" as the runtime. :type role: string :param role: The Amazon Resource Name (ARN) of the IAM role that Lambda assumes when it executes your function to access any other Amazon Web Services (AWS) resources. :type handler: string :param handler: The function that Lambda calls to begin execution. For Node.js, it is the module-name . export value in your function. :type mode: string :param mode: How the Lambda function will be invoked. Lambda supports only the "event" mode. :type description: string :param description: A short, user-defined function description. Lambda does not use this value. Assign a meaningful description as you see fit. :type timeout: integer :param timeout: The function execution time at which Lambda should terminate the function. Because the execution time has cost implications, we recommend you set this value based on your expected execution time. The default is 3 seconds. :type memory_size: integer :param memory_size: The amount of memory, in MB, your Lambda function is given. Lambda uses this memory size to infer the amount of CPU allocated to your function. Your function use-case determines your CPU and memory requirements. For example, database operation might need less memory compared to image processing function. The default value is 128 MB. The value must be a multiple of 64 MB. r4NRuntimerr]Moder^r_r`zGFile-like object passed to parameter ``function_zip`` must be seekable.rDrar#rF)rr, function_zipruntimer-rbmodercrdrer0r&r1rSrrrupload_functionsD >  z#AWSLambdaConnection.upload_functionc Cs|duri}tj||||||d}|d}|rt|}|j|kr&|S|ddd} |j | |j } | |j|j |)N)r&r%r'zutf-8zx-amzn-ErrorType:r) rr)readdecoderloadsstatus getheadersplit_faultsr ResponseErrorreason) rverbresourcer&r%r$r'responsebody error_type error_classrrrr)s   z AWSLambdaConnection.make_request)NN)NNNN)NNNNN)NNN)NrnNN)__name__ __module__ __qualname____doc__ APIVersionrrrrwrrr r r rvrrr2r;r@rArCrTrZr[r\rfrmr) __classcell__rrrrrsF    C' ." A br) rN boto.compatrboto.exceptionrboto.connectionrboto.regioninforboto.awslambdarrrrrrs