From 9a308d44186eaee590535d0448cea765d300ba0a Mon Sep 17 00:00:00 2001 From: Islam Shehata Date: Mon, 22 Jul 2024 14:09:56 +0300 Subject: [PATCH] simplify lambda and log group names --- cloudformation-stacks/forwarder.template.yaml | 8 ++------ cloudformation-stacks/subscriber.template.yaml | 8 ++------ cloudformation-stacks/unsubscriber.template.yaml | 9 ++------- subscriber.py | 4 +--- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/cloudformation-stacks/forwarder.template.yaml b/cloudformation-stacks/forwarder.template.yaml index d2c9b7a..46c9471 100644 --- a/cloudformation-stacks/forwarder.template.yaml +++ b/cloudformation-stacks/forwarder.template.yaml @@ -19,15 +19,11 @@ Parameters: DataTags: Type: String Description: Tags to be included with the data ingested into Axiom, e.g., =,=. - ForwarderLambdaName: - Type: String - Description: The name of the Forwarder Lambda function. - Default: "forwarder" Resources: ForwarderLogGroup: Type: "AWS::Logs::LogGroup" Properties: - LogGroupName: !Sub "/aws/axiom/${AWS::StackName}-${ForwarderLambdaName}" + LogGroupName: !Sub "/aws/axiom/${AWS::StackName}" RetentionInDays: 1 Tags: - Key: "Role" @@ -48,7 +44,7 @@ Resources: ForwarderLambda: Type: AWS::Lambda::Function Properties: - FunctionName: !Join ["-", [!Ref ForwarderLambdaName, !Ref AWS::StackName]] + FunctionName: !Ref AWS::StackName Runtime: python3.9 Handler: index.lambda_handler Code: diff --git a/cloudformation-stacks/subscriber.template.yaml b/cloudformation-stacks/subscriber.template.yaml index d7c05ae..1a800b9 100644 --- a/cloudformation-stacks/subscriber.template.yaml +++ b/cloudformation-stacks/subscriber.template.yaml @@ -14,10 +14,6 @@ Metadata: - CloudWatchLogGroupsPattern Parameters: - LambdaFunctionName: - Type: String - Description: The name of the Subscriber Lambda function. - Default: "subscriber" AxiomCloudWatchForwarderLambdaARN: Type: String Description: The ARN of the Axiom CloudWatch Forwarder Lambda function used to ship logs to Axiom. @@ -54,7 +50,7 @@ Resources: SubscriberLogGroup: Type: "AWS::Logs::LogGroup" Properties: - LogGroupName: !Sub "/aws/axiom/${AWS::StackName}-${LambdaFunctionName}" + LogGroupName: !Sub "/aws/axiom/${AWS::StackName}" RetentionInDays: 1 Tags: - Key: "Role" @@ -75,7 +71,7 @@ Resources: SubscriberLambda: Type: AWS::Lambda::Function Properties: - FunctionName: !Sub "${AWS::StackName}-${LambdaFunctionName}" + FunctionName: !Sub "${AWS::StackName}" Runtime: python3.9 Handler: index.lambda_handler Timeout: 300 diff --git a/cloudformation-stacks/unsubscriber.template.yaml b/cloudformation-stacks/unsubscriber.template.yaml index 60e89ec..7f2cf07 100644 --- a/cloudformation-stacks/unsubscriber.template.yaml +++ b/cloudformation-stacks/unsubscriber.template.yaml @@ -14,10 +14,6 @@ Metadata: - CloudWatchLogGroupsPattern Parameters: - LambdaFunctionName: - Type: String - Description: The name of the Unsubscriber Lambda function. - Default: "unsubscriber" AxiomCloudWatchForwarderLambdaARN: Type: String Description: The ARN of the Axiom CloudWatch Forwarder Lambda function used to forward logs to Axiom. @@ -54,8 +50,7 @@ Resources: UnsubscriberLogGroup: Type: "AWS::Logs::LogGroup" Properties: - LogGroupName: !Sub - - "/aws/axiom/${AWS::StackName}-${LambdaFunctionName}" + LogGroupName: !Sub "/aws/axiom/${AWS::StackName}" RetentionInDays: 1 Tags: - Key: "Role" @@ -76,7 +71,7 @@ Resources: UnsubscriberLambda: Type: AWS::Lambda::Function Properties: - FunctionName: !Sub "${AWS::StackName}-unsubscriber" + FunctionName: !Sub "${AWS::StackName}" Runtime: python3.9 Handler: index.lambda_handler Timeout: 300 diff --git a/subscriber.py b/subscriber.py index 8bd708a..4efc4cc 100644 --- a/subscriber.py +++ b/subscriber.py @@ -133,9 +133,7 @@ def lambda_handler(event: dict, context=None): try: remove_permission(statement_id, axiom_cloudwatch_forwarder_lambda_arn) except Exception as e: - logger.warning( - f"failed to remove permission for {cleaned_name}: {str(e)}" - ) + logger.warning(f"failed to remove permission for {cleaned_name}: {str(e)}") try: add_permission(