File tree Expand file tree Collapse file tree 4 files changed +38
-4
lines changed
Expand file tree Collapse file tree 4 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -39,8 +39,8 @@ data "aws_iam_policy_document" "codedeploy_lambda" {
3939 " lambda:ListVersionsByFunction" ,
4040 ]
4141 resources = [
42- aws_lambda_function . fn . arn ,
43- " ${ aws_lambda_function . fn . arn } :*" ,
42+ aws_lambda_function . lambda . arn ,
43+ " ${ aws_lambda_function . lambda . arn } :*" ,
4444 ]
4545 }
4646
@@ -51,3 +51,21 @@ data "aws_iam_policy_document" "codedeploy_lambda" {
5151 resources = [" *" ]
5252 }
5353}
54+
55+ data "aws_iam_policy_document" "lambda_iam_policy" {
56+ statement {
57+ sid = " AllowLambdaCloudwatchLogGroupPut"
58+
59+ actions = [
60+ " logs:CreateLogStream" ,
61+ " logs:PutLogEvents"
62+ ]
63+
64+ effect = " Allow"
65+
66+ resources = [
67+ " ${ aws_cloudwatch_log_group . lambda_cloudwatch_group . arn } " ,
68+ " ${ aws_cloudwatch_log_group . lambda_cloudwatch_group . arn } :*"
69+ ]
70+ }
71+ }
Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ resource "aws_lambda_function" "lambda" {
2525 }
2626}
2727
28+ resource "aws_cloudwatch_log_group" "lambda_cloudwatch_group" {
29+ name = " /aws/lambda/${ local . lambda_name } "
30+ retention_in_days = var. log_retention_days
31+ }
32+
2833resource "aws_lambda_alias" "live" {
2934 name = var. environment
3035 function_name = aws_lambda_function. lambda . arn
@@ -62,4 +67,4 @@ resource "aws_codedeploy_deployment_group" "dg" {
6267 enabled = true
6368 events = [" DEPLOYMENT_FAILURE" , " DEPLOYMENT_STOP_ON_ALARM" ]
6469 }
65- }
70+ }
Original file line number Diff line number Diff line change @@ -4,4 +4,8 @@ output "name" {
44
55output "arn" {
66 value = aws_lambda_function. lambda . arn
7- }
7+ }
8+
9+ output "cloudwatch_log_group" {
10+ value = aws_cloudwatch_log_group. lambda_cloudwatch_group . name
11+ }
Original file line number Diff line number Diff line change @@ -27,3 +27,10 @@ variable "lambda_version" {
2727 description = " Lambda code version to be deployed. Used in locating zip file keys"
2828}
2929# ## end of dynamic vars required for resources ###
30+
31+
32+ variable "log_retention_days" {
33+ type = number
34+ description = " Number of days to hold logs"
35+ default = 1
36+ }
You can’t perform that action at this time.
0 commit comments