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

update statmentId for the cloudwatch integrations[CDS-1408] #110

Merged
merged 5 commits into from
Jul 30, 2024
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog

## v1.0.11 / 2024-07-30
### 🧰 Bug fixes 🧰
- fix bug when trying to deploy CloudWatch integration. deploy with log group, with a name longer than 70 letters hit a limit with aws permission length, update the function so in case that the name is longer than 70 letters it will take the first 65 letters and the last 5.

## v1.0.10 / 2024-07-23
### 💡 Enhancements 💡
- Improved tamplate.yaml
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "coralogix-aws-shipper"
version = "1.0.10"
version = "1.0.11"
edition = "2021"

[dependencies]
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ Coralogix can be configured to receive data directly from your CloudWatch log gr
| CloudWatchLogGroupName | Provide a comma-separated list of CloudWatch log group names to monitor, for example, (`log-group1`, `log-group2`, `log-group3`). | | :heavy_check_mark: |
| CloudWatchLogGroupPrefix | Prefix of the CloudWatch log groups that will trigger the lambda, in case that your log groups are `log-group1, log-group2, log-group3` then you can set the value to `log-group`. When using this variable you will not be able to see the log groups as trigger for the lambda. The parameter dose not replace **CloudWatchLogGroupName** parameter | | |

In case your log group name is longer than 70, than in the lambda function you will see the permission for that log group as:
`allow-trigger-from-<the log group first 65 characters and the last 5 characters>` this is because of length limit in AWS for permission name.

### SNS Configuration

To receive SNS messages directly to Coralogix, use the `SNSIntegrationTopicARN` parameter. This differs from the above use of `SNSTopicArn`, which notifies based on S3 events.
Expand Down
15 changes: 12 additions & 3 deletions custom-resource/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,11 @@ def create(self):

if LambdaPremissionPrefix and LambdaPremissionPrefix != [""]:
for prefix in LambdaPremissionPrefix:
replaced_prefix = self.check_statmentid_length(prefix)
try:
self.aws_lambda.add_permission(
FunctionName=lambda_arn,
StatementId=f'allow-trigger-from-{prefix.replace("/", "-")}-log-groups',
StatementId=f'allow-trigger-from-{replaced_prefix.replace("/", "-")}-log-groups',
Action='lambda:InvokeFunction',
Principal='logs.amazonaws.com',
SourceArn=f'arn:aws:logs:{region}:{account_id}:log-group:{prefix}*:*',
Expand All @@ -427,9 +428,10 @@ def create(self):
)
if not LambdaPremissionPrefix or LambdaPremissionPrefix == [""]:
if not response.get("subscriptionFilters") or response.get("subscriptionFilters")[0].get("destinationArn") != lambda_arn:
replaced_prefix = self.check_statmentid_length(log_group)
response = self.aws_lambda.add_permission(
FunctionName=lambda_arn,
StatementId=f'allow-trigger-from-{log_group.replace("/", "-")}',
StatementId=f'allow-trigger-from-{replaced_prefix.replace("/", "-")}',
Action='lambda:InvokeFunction',
Principal='logs.amazonaws.com',
SourceArn=f'arn:aws:logs:{region}:{account_id}:log-group:{log_group}:*',
Expand All @@ -442,6 +444,12 @@ def create(self):
logGroupName=log_group
)

def check_statmentid_length(self, statmentid_prefix):
updated_prefix = statmentid_prefix
guyrenny marked this conversation as resolved.
Show resolved Hide resolved
if len(statmentid_prefix) >= 70: # StatementId length limit is 100
updated_prefix = statmentid_prefix[:65] + statmentid_prefix[-5:]
return updated_prefix

@handle_exceptions
def update(self):
err = self.delete()
Expand All @@ -466,9 +474,10 @@ def delete(self):
logGroupName=log_group
)
if not LambdaPremissionPrefix:
replaced_prefix = self.check_statmentid_length(log_group)
response = self.aws_lambda.remove_permission(
FunctionName=lambda_arn,
StatementId=f'allow-trigger-from-{log_group.replace("/", "-")}'
StatementId=f'allow-trigger-from-{replaced_prefix.replace("/", "-")}'
)

def handle(self):
Expand Down
2 changes: 1 addition & 1 deletion template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Metadata:
- kinesis
- cloudfront
HomePageUrl: https://coralogix.com
SemanticVersion: 1.0.10
SemanticVersion: 1.0.11
SourceCodeUrl: https://github.com/coralogix/coralogix-aws-shipper

AWS::CloudFormation::Interface:
Expand Down
Loading