You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+57-17Lines changed: 57 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ see [documentation](https://www.terraform.io/docs/providers/aws/r/lambda_functio
37
37
38
38
### basic
39
39
40
-
see [example](examples/complete) for other configuration options
40
+
see [example](examples/complete) for more configuration options
41
41
42
42
```hcl
43
43
provider "aws" {
@@ -234,33 +234,68 @@ module "lambda" {
234
234
235
235
### with CloudWatch Logs configuration
236
236
237
-
The module will create a [CloudWatch Log Group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group)
238
-
for your Lambda function. It's retention period and [CloudWatch Logs subscription filters](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_subscription_filter)
239
-
to stream logs to other Lambda functions (e.g. to forward logs to Amazon OpenSearch Service) can be declared inline.
237
+
By default, the module will create and manage a [CloudWatch Log Group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) for your Lambda function.
238
+
It's possible to configure settings like retention time and [KMS encryption](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html)
239
+
for this log group.
240
240
241
-
The module will create the required [Lambda permissions](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) automatically.
242
-
Sending logs to CloudWatch can be disabled with `cloudwatch_logs_enabled = false`
241
+
In addition, the module also supports [advanced logging configuration](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs-loggroups.html)
242
+
which provides the ability to define a custom name for the module managed log group as well as specifying an existing log group to be used by the Lambda function instead.
to stream logs to other Lambda functions (e.g. to forward logs to Amazon OpenSearch Service) can be declared inline
246
+
for the module managed log group or an existing log group.
247
+
248
+
The module will create the required [IAM permissions](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) for CloudWatch logs automatically. Those permissions can be removed by setting `cloudwatch_logs_enabled = false`.
243
249
244
-
see [example](examples/with-cloudwatch-logs-subscription) for details
250
+
see [example](examples/cloudwatch-logs) for details
245
251
246
252
```hcl
247
253
module "lambda" {
248
254
// see above
249
255
250
-
// disable CloudWatch logs
256
+
// remove CloudWatch logs IAM permissions
251
257
// cloudwatch_logs_enabled = false
252
258
253
-
cloudwatch_logs_retention_in_days = 14
259
+
// configure module managed log group
260
+
cloudwatch_logs_log_group_class = "STANDARD"
261
+
cloudwatch_logs_retention_in_days = 7
262
+
cloudwatch_logs_skip_destroy = false
263
+
264
+
// advanced logging config including a custom CloudWatch log group managed by the module
265
+
logging_config = {
266
+
application_log_level = "INFO"
267
+
log_format = "JSON"
268
+
log_group = "/custom/my_function_name"
269
+
system_log_level = "WARN"
270
+
}
254
271
272
+
// register log subscription filters for the functions log group
255
273
cloudwatch_log_subscription_filters = {
256
-
lambda_1 = {
257
-
//see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_subscription_filter for available arguments
258
-
destination_arn = module.destination_1.arn
274
+
sub_1 = {
275
+
// see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_subscription_filter for available arguments
276
+
destination_arn = module.sub_1.arn
277
+
filter_pattern = "%Lambda%"
259
278
}
279
+
}
280
+
}
260
281
261
-
lambda_2 = {
262
-
destination_arn = module.destination_2.arn
263
-
}
282
+
resource "aws_cloudwatch_log_group" "existing" {
283
+
name = "/existing/${module.fixtures.output_function_name}"
284
+
retention_in_days = 1
285
+
}
286
+
287
+
module "sub_1" {
288
+
source = "../../"
289
+
290
+
// other required arguments
291
+
292
+
// disable creation of the module managed CloudWatch log group
293
+
create_cloudwatch_log_group = false
294
+
295
+
// advanced logging config using an external CloudWatch log group
For `image` deployment packages, the Lambda Insights extension needs to be added to the [container image](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-Getting-Started-docker.html):
289
324
290
325
```dockerfile
291
-
FROM public.ecr.aws/lambda/nodejs:12
326
+
FROM public.ecr.aws/lambda/nodejs:22
292
327
293
328
RUN curl -O https://lambda-insights-extension.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension.rpm && \
294
329
rpm -U lambda-insights-extension.rpm && \
@@ -312,7 +347,7 @@ see [examples](examples/deployment) for details.
|[aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity)| data source |
418
+
|[aws_cloudwatch_log_group.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/cloudwatch_log_group)| data source |
383
419
|[aws_iam_policy.lambda_insights](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy)| data source |
384
420
|[aws_iam_policy.tracing](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy)| data source |
385
421
|[aws_iam_policy.vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy)| data source |
@@ -400,7 +436,10 @@ No modules.
400
436
| <aname="input_cloudwatch_log_subscription_filters"></a> [cloudwatch\_log\_subscription\_filters](#input\_cloudwatch\_log\_subscription\_filters)| CloudWatch Logs subscription filter resources. Currently supports only Lambda functions as destinations. |`map(any)`|`{}`| no |
401
437
| <aname="input_cloudwatch_logs_enabled"></a> [cloudwatch\_logs\_enabled](#input\_cloudwatch\_logs\_enabled)| Enables your Lambda function to send logs to CloudWatch. The IAM role of this Lambda function will be enhanced with required permissions. |`bool`|`true`| no |
402
438
| <aname="input_cloudwatch_logs_kms_key_id"></a> [cloudwatch\_logs\_kms\_key\_id](#input\_cloudwatch\_logs\_kms\_key\_id)| The ARN of the KMS Key to use when encrypting log data. |`string`|`null`| no |
439
+
| <aname="input_cloudwatch_logs_log_group_class"></a> [cloudwatch\_logs\_log\_group\_class](#input\_cloudwatch\_logs\_log\_group\_class)| Specifies the log class of the log group. Possible values are: `STANDARD`, `INFREQUENT_ACCESS`, or `DELIVERY`. |`string`|`null`| no |
403
440
| <aname="input_cloudwatch_logs_retention_in_days"></a> [cloudwatch\_logs\_retention\_in\_days](#input\_cloudwatch\_logs\_retention\_in\_days)| Specifies the number of days you want to retain log events in the specified log group. Possible values are: 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653, and 0. If you select 0, the events in the log group are always retained and never expire. |`number`|`null`| no |
441
+
| <aname="input_cloudwatch_logs_skip_destroy"></a> [cloudwatch\_logs\_skip\_destroy](#input\_cloudwatch\_logs\_skip\_destroy)| Set to true if you do not wish the log group (and any logs it may contain) to be deleted at destroy time, and instead just remove the log group from the Terraform state. |`bool`|`false`| no |
442
+
| <aname="input_create_cloudwatch_log_group"></a> [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group)| Create and manage the CloudWatch Log Group for the Lambda function. Set to `false` to reuse an existing log group. |`bool`|`true`| no |
404
443
| <aname="input_description"></a> [description](#input\_description)| Description of what your Lambda Function does. |`string`|`""`| no |
405
444
| <aname="input_environment"></a> [environment](#input\_environment)| Environment (e.g. env variables) configuration for the Lambda function enable you to dynamically pass settings to your function code and libraries | <pre>object({<br/> variables = map(string)<br/> })</pre> |`null`| no |
406
445
| <aname="input_ephemeral_storage_size"></a> [ephemeral\_storage\_size](#input\_ephemeral\_storage\_size)| The size of your Lambda functions ephemeral storage (/tmp) represented in MB. Valid value between 512 MB to 10240 MB. |`number`|`512`| no |
@@ -415,6 +454,7 @@ No modules.
415
454
| <aname="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn)| Amazon Resource Name (ARN) of the AWS Key Management Service (KMS) key that is used to encrypt environment variables. If this configuration is not provided when environment variables are in use, AWS Lambda uses a default service key. If this configuration is provided when environment variables are not in use, the AWS Lambda API does not save this configuration and Terraform will show a perpetual difference of adding the key. To fix the perpetual difference, remove this configuration. |`string`|`""`| no |
416
455
| <aname="input_lambda_at_edge"></a> [lambda\_at\_edge](#input\_lambda\_at\_edge)| Enable Lambda@Edge for your Node.js or Python functions. Required trust relationship and publishing of function versions will be configured. |`bool`|`false`| no |
417
456
| <aname="input_layers"></a> [layers](#input\_layers)| List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function. |`list(string)`|`[]`| no |
| <aname="input_memory_size"></a> [memory\_size](#input\_memory\_size)| Amount of memory in MB your Lambda Function can use at runtime. |`number`|`128`| no |
419
459
| <aname="input_package_type"></a> [package\_type](#input\_package\_type)| The Lambda deployment package type. Valid values are Zip and Image. |`string`|`"Zip"`| no |
420
460
| <aname="input_publish"></a> [publish](#input\_publish)| Whether to publish creation/change as new Lambda Function Version. |`bool`|`false`| no |
| <aname="input_region"></a> [region](#input\_region)| n/a |`string`|`"eu-west-1"`| no |
53
+
54
+
## Outputs
55
+
56
+
| Name | Description |
57
+
|------|-------------|
58
+
| <aname="output_arn"></a> [arn](#output\_arn)| The Amazon Resource Name (ARN) identifying your Lambda Function. |
59
+
| <aname="output_cloudwatch_custom_log_group_arn"></a> [cloudwatch\_custom\_log\_group\_arn](#output\_cloudwatch\_custom\_log\_group\_arn)| The Amazon Resource Name (ARN) identifying the custom CloudWatch log group used by your Lambda function. |
60
+
| <aname="output_cloudwatch_custom_log_group_name"></a> [cloudwatch\_custom\_log\_group\_name](#output\_cloudwatch\_custom\_log\_group\_name)| The name of the custom CloudWatch log group. |
61
+
| <aname="output_cloudwatch_existing_log_group_arn"></a> [cloudwatch\_existing\_log\_group\_arn](#output\_cloudwatch\_existing\_log\_group\_arn)| The Amazon Resource Name (ARN) identifying the existing CloudWatch log group used by your Lambda function. |
62
+
| <aname="output_cloudwatch_existing_log_group_name"></a> [cloudwatch\_existing\_log\_group\_name](#output\_cloudwatch\_existing\_log\_group\_name)| The name of the existing CloudWatch log group. |
63
+
| <aname="output_function_name"></a> [function\_name](#output\_function\_name)| The unique name of your Lambda Function. |
64
+
| <aname="output_role_name"></a> [role\_name](#output\_role\_name)| The name of the IAM role attached to the Lambda Function. |
0 commit comments