salt.states.boto_lambda

Manage Lambda Functions

New in version 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.

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

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:

myprofile:
    keyid: GKTADJGHEIQSXMKKRBJ08H
    key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
        region: us-east-1
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
salt.states.boto_lambda.alias_absent(name, FunctionName, Name, region=None, key=None, keyid=None, profile=None)

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.

salt.states.boto_lambda.alias_present(name, FunctionName, Name, FunctionVersion, Description='', region=None, key=None, keyid=None, profile=None)

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.

salt.states.boto_lambda.event_source_mapping_absent(name, EventSourceArn, FunctionName, region=None, key=None, keyid=None, profile=None)

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.

salt.states.boto_lambda.event_source_mapping_present(name, EventSourceArn, FunctionName, StartingPosition, Enabled=True, BatchSize=100, region=None, key=None, keyid=None, profile=None)

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.

salt.states.boto_lambda.function_absent(name, FunctionName, region=None, key=None, keyid=None, profile=None)

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.

salt.states.boto_lambda.function_present(name, FunctionName, Runtime, Role, Handler, ZipFile=None, S3Bucket=None, S3Key=None, S3ObjectVersion=None, Description='', Timeout=3, MemorySize=128, Permissions=None, RoleRetries=5, region=None, key=None, keyid=None, profile=None, VpcConfig=None, Environment=None)

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:

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:

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

New in version 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.