amazon.aws.lambda module – Manage AWS Lambda functions
Note
This module is part of the amazon.aws collection (version 5.5.1).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install amazon.aws
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: amazon.aws.lambda
.
New in amazon.aws 5.0.0
Synopsis
Allows for the management of Lambda functions.
This module was originally added to
community.aws
in release 1.0.0.
Requirements
The below requirements are needed on the host that executes this module.
python >= 3.6
boto3 >= 1.18.0
botocore >= 1.21.0
Parameters
Parameter |
Comments |
---|---|
AWS access key ID. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The aws_access_key and profile options are mutually exclusive. The aws_access_key_id alias was added in release 5.1.0 for consistency with the AWS botocore SDK. The ec2_access_key alias has been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
The instruction set architecture that the function supports. Requires one of s3_bucket or zip_file. Requires botocore >= 1.21.51. Choices:
|
|
The location of a CA Bundle to use when validating SSL certificates. The |
|
A dictionary to modify the botocore configuration. Parameters can be found in the AWS documentation https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config. |
|
The parent object that contains the target Amazon Resource Name (ARN) of an Amazon SQS queue or Amazon SNS topic. |
|
Use a The Choices:
|
|
A short, user-defined function description. Lambda does not use this value. Assign a meaningful description as you see fit. Default: |
|
URL to connect to instead of the default AWS endpoints. While this can be used to connection to other AWS-compatible services the amazon.aws and community.aws collections are only tested against AWS. The The ec2_url and s3_url aliases have been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
A dictionary of environment variables the Lambda function is given. |
|
The function within your code that Lambda calls to begin execution. |
|
The KMS key ARN used to encrypt the function’s environment variables. |
|
A list of function layers to add to the function’s execution environment. Specify each layer by its ARN, including the version. |
|
The name or Amazon Resource Name (ARN) of the layer. Mutually exclusive with layer_version_arn. |
|
The ARN of the layer version. Mutually exclusive with layer_version_arn. |
|
The version number. Required when layer_name is provided, ignored if not. |
|
The amount of memory, in MB, your Lambda function is given. Default: |
|
The name you want to assign to the function you are uploading. Cannot be changed. |
|
A named AWS profile to use for authentication. See the AWS documentation for more information about named profiles https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html. The The profile option is mutually exclusive with the aws_access_key, aws_secret_key and security_token options. |
|
If purge_tags=true and tags is set, existing tags will be purged from the resource to match exactly what is defined by tags parameter. If the tags parameter is not set then tags will not be modified, even if purge_tags=True. Tag keys beginning with Choices:
|
|
The AWS region to use. For global services such as IAM, Route53 and CloudFront, region is ignored. The See the Amazon AWS documentation for more information http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region. The Support for the |
|
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. You may use the bare ARN if the role belongs to the same AWS account. Required when state=present. |
|
The runtime environment for the Lambda function you are uploading. Required when creating a function. Uses parameters as described in boto3 docs. Required when state=present. For supported list of runtimes, see https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html. |
|
Amazon S3 bucket name where the .zip file containing your deployment package is stored. If state=present then either zip_file or s3_bucket must be present. s3_bucket and s3_key are required together. |
|
The Amazon S3 object (the deployment package) key name you want to upload. s3_bucket and s3_key are required together. |
|
The Amazon S3 object (the deployment package) version you want to upload. |
|
AWS secret access key. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The secret_key and profile options are mutually exclusive. The aws_secret_access_key alias was added in release 5.1.0 for consistency with the AWS botocore SDK. The ec2_secret_key alias has been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
AWS STS session token for use with temporary credentials. See the AWS documentation for more information about access tokens https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys. The The security_token and profile options are mutually exclusive. Aliases aws_session_token and session_token were added in release 3.2.0, with the parameter being renamed from security_token to session_token in release 6.0.0. The security_token, aws_security_token, and access_token aliases have been deprecated and will be removed in a release after 2024-12-01. Support for the |
|
Create or delete Lambda function. Choices:
|
|
A dictionary representing the tags to be applied to the resource. If the tags parameter is not set then tags will not be modified. |
|
The function maximum execution time in seconds after which Lambda should terminate the function. Default: |
|
Set mode to ‘Active’ to sample and trace incoming requests with AWS X-Ray. Turned off (set to ‘PassThrough’) by default. Choices:
|
|
When set to Setting validate_certs=false is strongly discouraged, as an alternative, consider setting aws_ca_bundle instead. Choices:
|
|
List of VPC security group IDs to associate with the Lambda function. Required when vpc_subnet_ids is used. |
|
List of subnet IDs to run Lambda function in. Use this option if you need to access resources in your VPC. Leave empty if you don’t want to run the function in a VPC. If set, vpc_security_group_ids must also be set. |
|
A .zip file containing your deployment package If state=present then either zip_file or s3_bucket must be present. |
Notes
Note
Caution: For modules, environment variables and configuration files are read from the Ansible ‘host’ context and not the ‘controller’ context. As such, files may need to be explicitly copied to the ‘host’. For lookup and connection plugins, environment variables and configuration files are read from the Ansible ‘controller’ context and not the ‘host’ context.
The AWS SDK (boto3) that Ansible uses may also read defaults for credentials and other settings, such as the region, from its configuration files in the Ansible ‘host’ context (typically
~/.aws/credentials
). See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html for more information.
Examples
# Create Lambda functions
- name: looped creation
amazon.aws.lambda:
name: '{{ item.name }}'
state: present
zip_file: '{{ item.zip_file }}'
runtime: 'python2.7'
role: 'arn:aws:iam::123456789012:role/lambda_basic_execution'
handler: 'hello_python.my_handler'
vpc_subnet_ids:
- subnet-123abcde
- subnet-edcba321
vpc_security_group_ids:
- sg-123abcde
- sg-edcba321
environment_variables: '{{ item.env_vars }}'
tags:
key1: 'value1'
loop:
- name: HelloWorld
zip_file: hello-code.zip
env_vars:
key1: "first"
key2: "second"
- name: ByeBye
zip_file: bye-code.zip
env_vars:
key1: "1"
key2: "2"
# To remove previously added tags pass an empty dict
- name: remove tags
amazon.aws.lambda:
name: 'Lambda function'
state: present
zip_file: 'code.zip'
runtime: 'python2.7'
role: 'arn:aws:iam::123456789012:role/lambda_basic_execution'
handler: 'hello_python.my_handler'
tags: {}
# Basic Lambda function deletion
- name: Delete Lambda functions HelloWorld and ByeBye
amazon.aws.lambda:
name: '{{ item }}'
state: absent
loop:
- HelloWorld
- ByeBye
# Create Lambda functions with function layers
- name: looped creation
amazon.aws.lambda:
name: 'HelloWorld'
state: present
zip_file: 'hello-code.zip'
runtime: 'python2.7'
role: 'arn:aws:iam::123456789012:role/lambda_basic_execution'
handler: 'hello_python.my_handler'
layers:
- layer_version_arn: 'arn:aws:lambda:us-east-1:123456789012:layer:python27-env:7'
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The lambda function’s code returned by get_function in boto3. Returned: success |
|
The presigned URL you can use to download the function’s .zip file that you previously uploaded. The URL is valid for up to 10 minutes. Returned: success Sample: |
|
The repository from which you can download the function. Returned: success Sample: |
|
the lambda function’s configuration metadata returned by get_function in boto3 Returned: success |
|
The architectures supported by the function. Returned: successful run where botocore >= 1.21.51 Sample: |
|
The SHA256 hash of the function’s deployment package. Returned: success Sample: |
|
The size of the function’s deployment package in bytes. Returned: success Sample: |
|
The function’s dead letter queue. Returned: when the function has a dead letter queue configured Sample: |
|
The ARN of an SQS queue or SNS topic. Returned: when the function has a dead letter queue configured Sample: |
|
The function’s description. Returned: success Sample: |
|
The function’s environment variables. Returned: when environment variables exist |
|
Error message for environment variables that could not be applied. Returned: when there is an error applying environment variables |
|
The error code. Returned: when there is an error applying environment variables |
|
The error message. Returned: when there is an error applying environment variables |
|
Environment variable key-value pairs. Returned: when environment variables exist Sample: |
|
The function’s Amazon Resource Name (ARN). Returned: on success Sample: |
|
The function’s name. Returned: on success Sample: |
|
The function Lambda calls to begin executing your function. Returned: on success Sample: |
|
The date and time that the function was last updated, in ISO-8601 format (YYYY-MM-DDThh:mm:ssTZD). Returned: on success Sample: |
|
The function’s layers. Returned: on success |
|
The Amazon Resource Name (ARN) of the function layer. Returned: always Sample: |
|
The size of the layer archive in bytes. Returned: always |
|
The Amazon Resource Name (ARN) of a signing job. Returned: always |
|
The Amazon Resource Name (ARN) for a signing profile version. Returned: always |
|
The memory allocated to the function. Returned: on success Sample: |
|
The latest updated revision of the function or alias. Returned: on success Sample: |
|
The function’s execution role. Returned: on success Sample: |
|
The funtime environment for the Lambda function. Returned: on success Sample: |
|
The amount of time that Lambda allows a function to run before terminating it. Returned: on success Sample: |
|
The function’s AWS X-Ray tracing configuration. Returned: on success Sample: |
|
The tracing mode. Returned: on success Sample: |
|
The version of the Lambda function. Returned: on success Sample: |
|
The function’s networking configuration. Returned: on success Sample: |