3 O4\@sddlmZmZddlmZmZddlmZddlm Z ddl m Z GdddeZ Gdd d e Z Gd d d e ZGd d d e ZdS)) ResourceMacro PropertyType)is_typeis_str)LambdaEventSourceMapping) ArnGenerator)InvalidEventExceptionc@sheZdZdZdZedeedeedeeedeedee dZ ddZ ddZ d d Z dS) PullEventSourceaBase class for pull event sources for SAM Functions. The pull events are Kinesis Streams, DynamoDB Streams, and SQS Queues. All of these correspond to an EventSourceMapping in Lambda, and require that the execution role be given to Kinesis Streams, DynamoDB Streams, or SQS Queues, respectively. :cvar str policy_arn: The ARN of the AWS managed role policy corresponding to this pull event source NF)StreamQueue BatchSizeStartingPositionEnabledcCs tddS)Nz#Subclass must implement this method)NotImplementedError)selfr/Users/sshvans/Documents/Work/Quickstart/python-virtual-environments/env/lib/python3.6/site-packages/samtranslator/model/eventsources/pull.pyget_policy_arnszPullEventSource.get_policy_arnc Ks|jd}|stdg}t|j}|j|y|jd}Wntk rZ|jd}YnX|j rx|j rxt |j d|jr|j rt |j d||_ |jp|j|_ |j |_ |j|_|j|_d|jkr|jd|jdd|kr|j|d|S) aReturns the Lambda EventSourceMapping to which this pull event corresponds. Adds the appropriate managed policy to the function's execution role, if such a role is provided. :param dict kwargs: a dict containing the execution role generated for the function :returns: a list of vanilla CloudFormation Resources, to which this pull event expands :rtype: list functionz+Missing required keyword argument: functionnameZarnz@No Queue (for SQS) or Stream (for Kinesis or DynamoDB) provided.z6StartingPosition is required for Kinesis and DynamoDB. Conditionrole)get TypeErrorrZ logical_idappendZget_runtime_attrrr r rZ relative_idr Z FunctionNameZEventSourceArnr rZresource_attributesZset_resource_attribute _link_policy)rkwargsrZ resourcesZlambda_eventsourcemappingZfunction_name_or_arnrrrto_cloudformations4      z!PullEventSource.to_cloudformationcCs*|j}|dk r&||jkr&|jj|dS)zIf this source triggers a Lambda function whose execution role is auto-generated by SAM, add the appropriate managed policy to this Role. :param model.iam.IAMROle role: the execution role generated for the function N)rZManagedPolicyArnsr)rrZ policy_arnrrrrKszPullEventSource._link_policy)__name__ __module__ __qualname____doc__ resource_typerrrintboolZproperty_typesrrrrrrrr s    -r c@seZdZdZdZddZdS)KinesiszKinesis event source.cCs tjdS)Nz*service-role/AWSLambdaKinesisExecutionRole)rgenerate_aws_managed_policy_arn)rrrrrZszKinesis.get_policy_arnN)rrr r!r"rrrrrr%Vsr%c@seZdZdZdZddZdS)DynamoDBzDynamoDB Streams event source.cCs tjdS)Nz+service-role/AWSLambdaDynamoDBExecutionRole)rr&)rrrrrbszDynamoDB.get_policy_arnN)rrr r!r"rrrrrr'^sr'c@seZdZdZdZddZdS)SQSzSQS Queue event source.cCs tjdS)Nz+service-role/AWSLambdaSQSQueueExecutionRole)rr&)rrrrrjszSQS.get_policy_arnN)rrr r!r"rrrrrr(fsr(N)Zsamtranslator.modelrrZsamtranslator.model.typesrrZsamtranslator.model.lambda_rZ&samtranslator.translator.arn_generatorrZsamtranslator.model.exceptionsrr r%r'r(rrrrs   M