%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/states/boto_lambda.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlm	Z	ddl
Zddlj
jZddlZddlZddlmZeje�Zd�Zddddddd	dd
ddddddd�Zddddd�Zddddd
�Zd�Zd�Zd�Zddddd�Zdddddd�Zddddd�Z ddddd�Z!e"dddddd�Z#ddddd�Z$dS(u
Manage Lambda Functions
=======================

.. versionadded:: 2016.3.0

Create and destroy Lambda Functions. Be aware that this interacts with Amazon's services,
and so may incur charges.

:depends:
    - boto
    - boto3

The dependencies listed above can be installed via package or pip.

This module accepts explicit vpc credentials but can also utilize
IAM roles assigned to the instance through Instance Profiles. Dynamic
credentials are then automatically obtained from AWS API and no further
configuration is necessary. More information available `here
<http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html>`_.

If IAM roles are not used you need to specify them either in a pillar file or
in the minion's config file:

.. code-block:: yaml

    vpc.keyid: GKTADJGHEIQSXMKKRBJ08H
    vpc.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

It's also possible to specify ``key``, ``keyid`` and ``region`` via a profile,
either passed in as a dict, or as a string to pull from pillars or minion
config:

.. code-block:: yaml

    myprofile:
        keyid: GKTADJGHEIQSXMKKRBJ08H
        key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
            region: us-east-1

.. code-block:: yaml

    Ensure function exists:
        boto_lambda.function_present:
            - FunctionName: myfunction
            - Runtime: python2.7
            - Role: iam_role_name
            - Handler: entry_function
            - ZipFile: code.zip
            - S3Bucket: bucketname
            - S3Key: keyname
            - S3ObjectVersion: version
            - Description: "My Lambda Function"
            - Timeout: 3
            - MemorySize: 128
            - region: us-east-1
            - keyid: GKTADJGHEIQSXMKKRBJ08H
            - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

i(tabsolute_importtprint_functiontunicode_literalsN(tsix(tSaltInvocationErrorcC@sdtkrdStS(u)
    Only load if boto is available.
    uboto_lambda.function_existsuboto_lambda(t__salt__tFalse(((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pyt__virtual__Psuii�ic'C@s�i|d6td6dd6id6}|d7k	rt|tj�rXtjjj|�}nt	d8�}t	d9�}x�tj
|�D]�\}}t	|j��}|j|�s�t
djdj|����n||}||}t|�r�t
d
jdj|����q�q�Wntdd|d|d|d|d|�}d|krvt|d<dj|dd�|d<|S|jd�s�tdr�dj|�|d<d7|d<|Stdd|d|d|d|d|d|d |d!|d"|	d#|
d$|d%|d&|d'td(|
d|d|d|d|�}|jd)�sgt|d<dj|dd�|d<|S|r�x�tj
|�D]w\}}td*d|d+|d|d|d|d||�}|jd,�s}t|d<dj|dd�|d<q}q}Wntd-|d|d|d|d|�}td.|d|d|d|d|�d/|d0d1<id7d06|dd2<||dd3<d4j|�|d<|Stjj|dd5j|�g�|d<i|d<t||||	|
||||||||
�
}|jd�s5|jdt�|d<|d|d<i|d<|Stj|d|d�|d<d6j|d|dg�|d<t|||||||||�	}|jd�s�|jdt�|d<|d|d<i|d<|Stj|d|d�|d<d6j|d|dg�|d<t||||||�}|jd�st|jdt�|d<|d|d<i|d<|Stj|d|d�|d<d6j|d|dg�|d<|S(:u�
    Ensure function exists.

    name
        The name of the state definition

    FunctionName
        Name of the Function.

    Runtime
        The Runtime environment for the function. One of
        'nodejs', 'java8', or 'python2.7'

    Role
        The name or ARN of the IAM role that the function assumes when it executes your
        function to access any other AWS resources.

    Handler
        The function within your code that Lambda calls to begin execution. For Node.js it is the
        module-name.*export* value in your function. For Java, it can be package.classname::handler or
        package.class-name.

    ZipFile
        A path to a .zip file containing your deployment package. If this is
        specified, S3Bucket and S3Key must not be specified.

    S3Bucket
        Amazon S3 bucket name where the .zip file containing your package is
        stored. If this is specified, S3Key must be specified and ZipFile must
        NOT be specified.

    S3Key
        The Amazon S3 object (the deployment package) key name you want to
        upload. If this is specified, S3Key must be specified and ZipFile must
        NOT be specified.

    S3ObjectVersion
        The version of S3 object to use. Optional, should only be specified if
        S3Bucket and S3Key are specified.

    Description
        A short, user-defined function description. Lambda does not use this value. Assign a meaningful
        description as you see fit.

    Timeout
        The function execution time at which Lambda should terminate this 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.

    MemorySize
        The amount of memory, in MB, your function is given. Lambda uses this memory size to infer
        the amount of CPU and memory 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.

    VpcConfig
        If your Lambda function accesses resources in a VPC, you must provide this parameter
        identifying the list of security group IDs/Names and subnet IDs/Name.  These must all belong
        to the same VPC.  This is a dict of the form:

        .. code-block:: yaml

            VpcConfig:
              SecurityGroupNames:
                - mysecgroup1
                - mysecgroup2
              SecurityGroupIds:
                - sg-abcdef1234
              SubnetNames:
                - mysubnet1
              SubnetIds:
                - subnet-1234abcd
                - subnet-abcd1234

        If VpcConfig is provided at all, you MUST pass at least one security group and one subnet.

    Permissions
        A list of permission definitions to be added to the function's policy

    RoleRetries
        IAM Roles may take some time to propagate to all regions once created.
        During that time function creation may fail; this state will
        atuomatically retry this number of times. The default is 5.

    Environment
        The parent object that contains your environment's configuration
        settings.  This is a dictionary of the form:

        .. code-block:: python

            {
                'Variables': {
                    'VariableName': 'VariableValue'
                }
            }

        .. versionadded:: 2017.7.0

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    unameuresultuucommentuchangesuActionu	Principalu	SourceArnu
SourceAccountu	Qualifieru2{0} are required for each permission specificationu, uInvalid permission value {0}uboto_lambda.function_existstFunctionNametregiontkeytkeyidtprofileuerroruFailed to create function: {0}.umessageuexistsutestu"Function {0} is set to be created.uboto_lambda.create_functiontRuntimetRoletHandlertZipFiletS3BuckettS3KeytS3ObjectVersiontDescriptiontTimeoutt
MemorySizet	VpcConfigtEnvironmenttWaitForRoletRoleRetriesucreateduboto_lambda.add_permissiontStatementIduupdateduboto_lambda.describe_functionuboto_lambda.get_permissionsupermissionsufunctionuPermissionsuoldunewuFunction {0} created.uFunction {0} is present.u N(uActionu	Principal(u	SourceArnu
SourceAccountu	Qualifier(tTruetNonet
isinstanceRtstring_typestsalttutilstjsontloadstsett	iteritemstkeyst
issupersetRtformattjointboolRRtgett__opts__tostlinesept_function_config_presentt
dictupdatetupdatet_function_code_presentt_function_permissions_present(tnameRR
RRRRRRRRRtPermissionsRR	R
RRRRtrett
required_keyst
optional_keystsidt
permissiontkeysettrt	_describet_ret((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pytfunction_presentWs�v

	

%







	
!	 
	
!
!	
!c	C@sH|jd�r|Stdd|d|d|d|�}dj||�S(Nuarn:aws:iam:uboto_iam.get_account_idR	R
RRuarn:aws:iam::{0}:role/{1}(t
startswithRR((R4R	R
RRt
account_id((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pyt
_get_role_arn:s

c
C@s0t|tj�r*tjjj|�}n|sBigd6gd6St|t�s`td��ng|j	dg�D]:}t
dd|d|d|d	|d
|�jd�^qs}g|j	dg�D].}t
d
|d|d|d	|d
|�^q�}|jdg�j
|�|jdg�j
|�|S(Nu	SubnetIdsuSecurityGroupIdsuVpcConfig must be a dict.uSubnetNamesuboto_vpc.get_resource_idusubnetR	R
RRuiduSecurityGroupNamesuboto_secgroup.get_group_id(RRRR R!R"R#tdictRtpopRR+t
setdefaulttextend(tconfR	R
RRtstsnstsgs((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pyt_resolve_vpcconfigDsPDc
C@sitd6dd6id6}
td|d|d|	d|
d	|�d
}t|||	|
|�}t}idd6d
d
6dd6dd6dd6}x|tj|�D]k\}}||t�|kr�t}t�||
djdi�|<|||
djdi�|<q�q�W|jd�}|dk	r;|j
dd�nt|||	|
|�}td|�td|�kr�t}||
djdi�d<|jd�|
djdi�d<n|dk	r#|jd�|kr#t}||
djdi�d<|jd�|
djdi�d<q#n|rt
jj|
ddg�|
d<tdrtdj|�|
d<d|
d<|
Stdd|d|d|d|d|d |d!|d"|d|d|	d|
d	|d#td$|�}|jd%�st|
d<d&j|d'd(�|
d<i|
d<qn|
S()Nuresultuucommentuchangesuboto_lambda.describe_functionR	R
RRufunctionurole_arnuRoleuHandleruDescriptionuTimeoutu
MemorySizeunewuoldu	VpcConfiguVpcIdu
boto3.ordereduEnvironmentuFunction config to be modifiedutestu Function {0} set to be modified.u"boto_lambda.update_function_configRRRRRRRRRRuupdateduFailed to update function: {0}.uerrorumessage(RRRBRRR%tlocalsRER+RRDRKt	__utils__R-R.R)R,R((RRRRRRRRR	R
RRRR6tfunctrole_arntneed_updatetoptionstvaltvartoldvaltfixed_VpcConfigt_r((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pyR/Wsb

!% &#	


	
c	C@saitd6dd6id6}	td|d|d|d|d	|�d
}
t}|r�tjj|�}||
dkr�tj�}
tj	j
j|d��}|
j|j
��WdQX|
j�jd
�j�}||
dkr�t}q�q�t}nt}|r]tdr,dj|�|	d<d|	d<|	Si|
dd6|
dd6|	dd<td|||||d|d|d|d	|�}
|
jd�s�t|	d<dj|
dd�|	d<i|	d<|	S|
d
}
|
d|	dddks|
d|	dddkrOtjj|	ddg�|	d<i|
dd6|
dd6|	dd<q]|	dd=n|	S(Nuresultuucommentuchangesuboto_lambda.describe_functionR	R
RRufunctionuCodeSizeurbubase64u
CodeSha256utestu Function {0} set to be modified.uoldu boto_lambda.update_function_codeuupdateduFailed to update function: {0}.uerrorumessageuFunction code to be modifiedunew(RRRR-tpathtgetsizethashlibtsha256R R!tfilestfopenR1treadtdigesttencodetstripR,R(RR+R.R)(RRRRRR	R
RRR6RNR1tsizetshatfthashed((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pyR2�sX	

		


	cC@s�itd6dd6id6}td|d|d|d|d	|�jd
�}|dkrai}nt}tjjj||pi�}	t	|	�r�t
jj|ddg�|d<t
dr�d
j|�|d<d|d<|Sx�tj|	�D]�\}
}|jdd�dkr�tdd|d|
d|d|d|d	|�}i|djdi�jdi�|
<|d|djdi�jdi�|
<n|jdd�dkrLtdd|d|
d|d|d|d	||d�}|d|djdi�jdi�|
<|djdi�jdi�}
|
|
krLi|
|
<qLn|jd�s�t|d<dj|dd�|d<i|d<q�q�Wn|S(Nuresultuucommentuchangesuboto_lambda.get_permissionsR	R
RRupermissionsu#Function permissions to be modifiedutestu Function {0} set to be modified.uolduboto_lambda.remove_permissionRRunewuPermissionsuboto_lambda.add_permissionuupdateduFailed to update function: {0}.uerrorumessage(RRR+RRR R!tdatat
compare_dictsR*R-R.R)R,R(RR%RE(RR5R	R
RRR6tcurr_permissionsRPtdiffsR9tdiffRVtoldperms((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pyR3�sL		


&-

*

cC@sni|d6td6dd6id6}td|d|d|d	|d
|�}d|krt|d<dj|dd
�|d<|S|r�|dr�dj|�|d<|Stdr�dj|�|d<d|d<|Std|d|d|d	|d
|�}|ds-t|d<dj|dd
�|d<|Si|d6|dd<idd6|dd<dj|�|d<|S(u�
    Ensure function with passed properties is absent.

    name
        The name of the state definition.

    FunctionName
        Name of the function.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    unameuresultuucommentuchangesuboto_lambda.function_existsR	R
RRuerroruFailed to delete function: {0}.umessageuexistsuFunction {0} does not exist.utestu"Function {0} is set to be removed.uboto_lambda.delete_functionudeletedufunctionuoldunewuFunction {0} deleted.N(RRRR(R,R(R4RR	R
RRR6R<((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pytfunction_absent�s>

!







c	C@sUi|d6td6dd6id6}	tdd|d|d	|d
|d|d|�}
d
|
kr�t|	d<dj|
d
d�|	d<|	S|
jd�s�tdr�dj|�|	d<d$|	d<|	Std||||||||�}
|
jd�st|	d<dj|
d
d�|	d<|	Std||d	|d
|d|d|�}id$d6|	dd<||	dd<dj|�|	d<|	Stjj	|	ddj|�g�|	d<i|	d<td||d	|d
|d|d|�d}t}idd6dd6}
x|t
j|
�D]k\}}||t�|krt}t�||	dj
di�|<|||	dj
di�|<qqW|rQtjj	|	ddg�|	d<tdr�dj|�|	d<d$|	d<|	Stdd|d|d |d!|d	|d
|d|d|�}|jd"�sQt|	d<d#j|d
d�|	d<i|	d<qQn|	S(%u�
    Ensure alias exists.

    name
        The name of the state definition.

    FunctionName
        Name of the function for which you want to create an alias.

    Name
        The name of the alias to be created.

    FunctionVersion
        Function version for which you are creating the alias.

    Description
        A short, user-defined function description. Lambda does not use this value. Assign a meaningful
        description as you see fit.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    unameuresultuucommentuchangesuboto_lambda.alias_existsRtNameR	R
RRuerroruFailed to create alias: {0}.umessageuexistsutestuAlias {0} is set to be created.uboto_lambda.create_aliasucreateduboto_lambda.describe_aliasualiasuoldunewuAlias {0} created.uAlias {0} is present.uFunctionVersionuDescriptionuAlias config to be modifieduAlias {0} set to be modified.uboto_lambda.update_aliastFunctionVersionRuupdateduFailed to update alias: {0}.N(RRRR(R+R,RR-R.R)RR%RLRE(R4RRlRmRR	R
RRR6R<R=RPRQRRRSRV((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pyt
alias_present6s~"







	 



!%	



c	C@sti|d6td6dd6id6}td||d|d|d	|d
|�}d|kr�t|d<dj|dd
�|d<|S|r�|dr�dj|�|d<|Stdr�dj|�|d<d|d<|Std||d|d|d	|d
|�}|ds3t|d<dj|dd
�|d<|Si|d6|dd<idd6|dd<dj|�|d<|S(u�
    Ensure alias with passed properties is absent.

    name
        The name of the state definition.

    FunctionName
        Name of the function.

    Name
        Name of the alias.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    unameuresultuucommentuchangesuboto_lambda.alias_existsR	R
RRuerroruFailed to delete alias: {0}.umessageuexistsuAlias {0} does not exist.utestuAlias {0} is set to be removed.uboto_lambda.delete_aliasudeletedualiasuoldunewuAlias {0} deleted.N(RRRR(R,R(	R4RRlR	R
RRR6R<((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pytalias_absent�s>

	


	

c	C@s|jd�r|Stdd|d|d|d|�}|rWd|krW|d}n|dkrld}nd	j|||�S(
Nuarn:aws:lambda:uboto_iam.get_account_idR	R
RRuregionu	us-east-1u#arn:aws:lambda:{0}:{1}:function:{2}(R@RRR((R4R	R
RRRA((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pyt_get_function_arn�s

	idc
C@sid'd6td6dd6id6}
tdd|d|d	|d
|d|d|	�}d
|kr�t|
d<dj|d
d�|
d<|
S|jd�s�tdr�dj|�|
d<d'|
d<|
Stdd|d|d|d|d|d	|d
|d|d|	�	}|jd�s=t|
d<dj|d
d�|
d<|
Stdd|d|d	|d
|d|d|	�}|dd|
d<id'd6|
dd<||
dd<dj|
d�|
d<|
Stjj	|
ddg�|
d<i|
d<tdd|d|d	|d
|d|d|	�d}t}
idd6}x|t
j|�D]k\}}||t�|kr@t}
t�||
dj
di�|<|||
dj
di�|<q@q@Wt|d	|d
|d|d|	�}|d |kr$t}
||
dj
di�d <|d |
dj
di�d <n|
r�tjj	|
dd!g�|
d<tdryd"j|d�|
d<d'|
d<|
Std#d$|dd|d|d|d	|d
|d|d|	�}|jd%�s�t|
d<d&j|d
d�|
d<i|
d<q�n|
S((ug
    Ensure event source mapping exists.

    name
        The name of the state definition.

    EventSourceArn
        The Amazon Resource Name (ARN) of the Amazon Kinesis or the Amazon
        DynamoDB stream that is the event source.

    FunctionName
        The Lambda function to invoke when AWS Lambda detects an event on the
        stream.

        You can specify an unqualified function name (for example, "Thumbnail")
        or you can specify Amazon Resource Name (ARN) of the function (for
        example, "arn:aws:lambda:us-west-2:account-id:function:ThumbNail"). AWS
        Lambda also allows you to specify only the account ID qualifier (for
        example, "account-id:Thumbnail"). Note that the length constraint
        applies only to the ARN. If you specify only the function name, it is
        limited to 64 character in length.

    StartingPosition
        The position in the stream where AWS Lambda should start reading.
        (TRIM_HORIZON | LATEST)

    Enabled
        Indicates whether AWS Lambda should begin polling the event source. By
        default, Enabled is true.

    BatchSize
        The largest number of records that AWS Lambda will retrieve from your
        event source at the time of invoking your function. Your function
        receives an event with all the retrieved records. The default is 100
        records.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    unameuresultuucommentuchangesu'boto_lambda.event_source_mapping_existstEventSourceArnRR	R
RRuerroru+Failed to create event source mapping: {0}.umessageuexistsutestu.Event source mapping {0} is set to be created.u'boto_lambda.create_event_source_mappingtStartingPositiontEnabledt	BatchSizeucreatedu)boto_lambda.describe_event_source_mappinguevent_source_mappinguUUIDuoldunewu!Event source mapping {0} created.u Event source mapping is present.u	BatchSizeuFunctionArnu#Event source mapping to be modifiedu,Event source mapping {0} set to be modified.u'boto_lambda.update_event_source_mappingtUUIDuupdateduFailed to update mapping: {0}.N(RRRRR(R+R,R-R.R)RR%RLRERp(R4RqRRrRsRtR	R
RRR6R<R=RPRQRRRStfunction_arnRV((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pytevent_source_mapping_present�s�5







	

	



!%	



c

C@snidd6td6dd6id6}tdd|d|d	|d
|d|d|�}d
|kr�t|d<dj|d
d�|d<|S|jd�s�d|d<|S|dd|d<tdr�d|d<d|d<|Stdd|d|d	|d
|d|d|�}	|	ds=t|d<dj|	d
d�|d<|S||dd<idd6|dd<d|d<|S(u�
    Ensure event source mapping with passed properties is absent.

    name
        The name of the state definition.

    EventSourceArn
        ARN of the event source.

    FunctionName
        Name of the lambda function.

    region
        Region to connect to.

    key
        Secret key to be used.

    keyid
        Access key to be used.

    profile
        A dict with region, key and keyid, or a pillar key (string) that
        contains a dict with region, key and keyid.
    unameuresultuucommentuchangesu)boto_lambda.describe_event_source_mappingRqRR	R
RRuerroru+Failed to delete event source mapping: {0}.umessageuevent_source_mappingu$Event source mapping does not exist.uUUIDutestu*Event source mapping is set to be removed.u'boto_lambda.delete_event_source_mappingudeleteduoldunewuEvent source mapping deleted.N(RRRRR(R+R,(
R4RqRR	R
RRR6tdescR<((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pytevent_source_mapping_absent~s@












(%t__doc__t
__future__RRRtloggingR-RYtsalt.extRtsalt.utils.dataR tsalt.utils.dictupdateR!R0tsalt.utils.filestsalt.utils.jsontsalt.exceptionsRt	getLoggert__name__tlogRRR?RBRKR/R2R3RkRnRoRpRRwRy(((s;/usr/lib/python2.7/site-packages/salt/states/boto_lambda.pyt<module>=s@				�
	;	8	/=i@	�

Zerion Mini Shell 1.0