Lambdas#
Use this module to create lambdas for the project.
lambdas.ScheduledLambdas#
A lambda function scheduled by event bridge.
Terraform resources:
- IamRole: Role for the lambda.
- LambdaFunction; The lambda function.
- CloudwatchLogGroup: Log group for logging.
- CloudwatchEventRule: Schedule event rule.
- CloudwatchEventTarget: Attach event rule to the function.
- LambdaPermission; Allow invokation of the function from CloudWhatch.
Arguments
Name | Type | Description |
---|---|---|
name | str | Name of the lambda function |
schedule_expression | str | A valid scheduled expression, ex: 'rate(1 hour)' |
filename | str | Path to the zipfile containing lambda code |
policies | list | List of policies arn to attach to the function |
memory_size | int | Lambda memory size in MB |
timeout | int | Timeout of the function |
environement | dict | Environement variable to pass to the function |
tags | dict | Tags for all resource, must include a 'project' and 'env' key |
lambdas.InvokableLambdas#
A lambda function usable by other services.
Terraform resources:
- IamRole: Role for the lambda.
- LambdaFunction; The lambda function.
- CloudwatchLogGroup: Log group for logging.
- LambdaPermission; Allow invokation of the function from the consumer.
Arguments
Name | Type | Description |
---|---|---|
name | str | Name of the lambda function |
filename | str | Path to the zipfile containing lambda code |
policies | list | List of policies arn to attach to the function |
invoke_principal | str | Principal of the consumer of the lambda (lambda.amazonaws.com, ec2.amazonaws.com, etc.) |
invoke_from_arn | str | ARN of the consumer(s) |
memory_size | int | Lambda memory size in MB |
timeout | int | Timeout of the function |
environement | dict | Environement variable to pass to the function |
tags | dict | Tags for all resource, must include a 'project' and 'env' key |
Example#
Create a schudled lambda that runs every minute:
from src.lambdas import ScheduledLambdas
tags = {
"project": "My Project",
"env": "dev"
}
ScheduledLambdas(
self,
"lambda",
name="do-something-every-minute",
schedule_expression="rate(1 minute)",
filename="path/to/my/zipfile.zip",
policies=[read_my_db_policy_arn],
memory_size=512,
timeout=20,
environement={},
tags=tags,
)
Create a lambda that can be invoke in any lambda:
from src.lambdas import InvokableLambdas
InvokableLambdas(
self,
"lambda",
name="usefull-lambda",
filename="path/to/my/zipfile.zip",
policies=[],
invoke_principal="lambda.amazonaws.com",
invoke_from_arn="arn:aws:lambda:region:account-id:function:*",
memory_size=512,
timeout=20,
environement={},
tags=tags,
)