Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to choose s3 prefix/key as variable - default to AWS_ACCOUNT #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ This module creates:

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| cloudwatch\_logs\_export\_bucket | Bucket to export logs | `string` | `""` | no |
| runtime | Runtime version of the lambda function | `string` | `"python3.10"` | no |
| Name | Description | Type | Default | Required |
|----------------------------------|--------------------------------------------------------|------|---------------|:--------:|
| cloudwatch\_logs\_export\_bucket | Bucket to export logs | `string` | `""` | no |
| s3\_prefix | s3 Key where to export logs ( default to AWS_ACCOUNT ) | `string` | `null` | no |
| runtime | Runtime version of the lambda function | `string` | `"python3.10"` | no |

## Outputs

Expand Down
6 changes: 6 additions & 0 deletions _variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ variable "runtime" {
type = string
default = "python3.10"
description = "Runtime version of the lambda function"
}

variable "s3_prefix" {
type = string
default = null
description = "Key prefix where to store logs, defaulted to aws_account if not set"
}
2 changes: 1 addition & 1 deletion cloudwatch-logs-exporter.tf
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ resource "aws_lambda_function" "log_exporter" {
environment {
variables = {
S3_BUCKET = var.cloudwatch_logs_export_bucket,
AWS_ACCOUNT = data.aws_caller_identity.current.account_id
S3_PREFIX = coalesce(var.s3_prefix, data.aws_caller_identity.current.account_id)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lambda/cloudwatch-to-s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def lambda_handler(event, context):
fromTime=int(ssm_value),
to=export_to_time,
destination=os.environ['S3_BUCKET'],
destinationPrefix=os.environ['AWS_ACCOUNT'] + '/' + log_group_name.strip('/')
destinationPrefix=os.environ['S3_PREFIX'] + '/' + log_group_name.strip('/')
)
print(" Task created: %s" % response['taskId'])
ssm_response = ssm.put_parameter(
Expand Down
Binary file removed lambda/tmp/cloudwatch-to-s3.zip
Binary file not shown.