Skip to content

Commit

Permalink
Fix namings of LogGroupsListener in template and py code
Browse files Browse the repository at this point in the history
  • Loading branch information
dasfmi committed Jul 16, 2024
1 parent c4eb99e commit c0505ad
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
mkdir build
yq ".Resources.LogsLambda.Properties.Code.ZipFile = \"$(sed 's/\"/\\\"/g' ./handler.py)\"" cloudformation-stacks/forwarder.template.yaml > build/axiom-cloudwatch-forwarder-cloudformation-stack.yaml
yq ".Resources.SubscriberLambda.Properties.Code.ZipFile = \"$(sed 's/\"/\\\"/g' ./subscriber.py)\"" cloudformation-stacks/subscriber.template.yaml > build/axiom-cloudwatch-subscriber-cloudformation-stack.yaml
yq ".Resources.AxiomCloudWatchLogsSubscriber.Properties.Code.ZipFile = \"$(sed 's/\"/\\\"/g' ./logs_subscriber.py)\"" cloudformation-stacks/log-groups-listener.template.yaml > build/axiom-cloudwatch-log-groups-listener-cloudformation-stack.yaml
yq ".Resources.AxiomCloudWatchLogGroupsListener.Properties.Code.ZipFile = \"$(sed 's/\"/\\\"/g' ./logs_subscriber.py)\"" cloudformation-stacks/log-groups-listener.template.yaml > build/axiom-cloudwatch-log-groups-listener-cloudformation-stack.yaml
- run: cat build/*
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
mkdir build
yq ".Resources.LogsLambda.Properties.Code.ZipFile = \"$(sed 's/\"/\\\"/g' ./handler.py)\"" cloudformation-stacks/forwarder.template.yaml > build/axiom-cloudwatch-forwarder-cloudformation-stack.yaml
yq ".Resources.SubscriberLambda.Properties.Code.ZipFile = \"$(sed 's/\"/\\\"/g' ./subscriber.py)\"" cloudformation-stacks/subscriber.template.yaml > build/axiom-cloudwatch-subscriber-cloudformation-stack.yaml
yq ".Resources.AxiomCloudWatchLogsSubscriber.Properties.Code.ZipFile = \"$(sed 's/\"/\\\"/g' ./logs_subscriber.py)\"" cloudformation-stacks/subscriber.template.yaml > build/axiom-cloudwatch-log-groups-listener-cloudformation-stack.yaml
yq ".Resources.AxiomCloudWatchLogGroupsListener.Properties.Code.ZipFile = \"$(sed 's/\"/\\\"/g' ./logs_subscriber.py)\"" cloudformation-stacks/subscriber.template.yaml > build/axiom-cloudwatch-log-groups-listener-cloudformation-stack.yaml
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down
64 changes: 32 additions & 32 deletions cloudformation-stacks/log-groups-listener.template.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Description: A lambda function to auto subscribe Axiom Forwarder to new CloudWatch Log Groups.
Description: A lambda function to auto subscribe Axiom CloudWatch Forwarder to new log groups.
Parameters:
LambdaFunctionName:
Type: String
Description: Name of the AWS Lambda Function.
Default: cloudwatch-subscriber-axiom
Description: Name of the AWS Lambda function.
Default: axiom-cloudwatch-log-groups-listener
AllowedPattern: ".+" # required
AxiomCloudWatchLambdaIngesterARN:
AxiomCloudWatchForwarderLambdaARN:
Type: String
Description: The ARN of the AWS Lambda Function that is used to ingest data to axiom.
Description: The ARN of the AWS Lambda function that is used to shi[] logs to Axiom.
AllowedPattern: ".+" # required
CloudWatchLogGroupsPrefix:
Type: String
Description: The Prefix of cloudwatch log groups to subscribe to the AWS Lambda ingester.
Description: The Prefix of CloudWatch log groups to trigger the Axiom CloudWatch Forwarder lambda.
Default: "" # all
AxiomLambdaLogRetention:
Type: "Number"
Expand All @@ -25,18 +25,18 @@ Parameters:
Conditions:
ShouldEnableCloudTrail: !Equals [true, !Ref EnableCloudTrail]
Resources:
AxiomCloudWatchLogsSubscriberS3Bucket:
AxiomCloudWatchLogGroupsListenerS3Bucket:
Condition: ShouldEnableCloudTrail
Type: AWS::S3::Bucket
Properties:
AccessControl: BucketOwnerFullControl
BucketName: !Join ["-", [!Ref AWS::StackName, "cloudtrail"]]
AxiomCloudWatchLogsSubscriberS3BucketPolicy:
AxiomCloudWatchLogGroupsListenerS3BucketPolicy:
Type: AWS::S3::BucketPolicy
Condition: ShouldEnableCloudTrail
DependsOn: AxiomCloudWatchLogsSubscriberS3Bucket
DependsOn: AxiomCloudWatchLogGroupsListenerS3Bucket
Properties:
Bucket: !Ref AxiomCloudWatchLogsSubscriberS3Bucket
Bucket: !Ref AxiomCloudWatchLogGroupsListenerS3Bucket
PolicyDocument:
{
"Version": "2012-10-17",
Expand All @@ -48,7 +48,7 @@ Resources:
"Principal": { "Service": "cloudtrail.amazonaws.com" },
"Action": "s3:GetBucketAcl",
"Resource":
!GetAtt ["AxiomCloudWatchLogsSubscriberS3Bucket", "Arn"],
!GetAtt ["AxiomCloudWatchLogGroupsListenerS3Bucket", "Arn"],
},
{
"Sid": "AWSCloudTrailWrite20150319",
Expand All @@ -59,7 +59,7 @@ Resources:
!Join [
"",
[
!GetAtt ["AxiomCloudWatchLogsSubscriberS3Bucket", "Arn"],
!GetAtt ["AxiomCloudWatchLogGroupsListenerS3Bucket", "Arn"],
"/AWSLogs/",
{ "Ref": "AWS::AccountId" },
"/*",
Expand All @@ -73,19 +73,19 @@ Resources:
},
],
}
AxiomLogsSubscriberCloudTrail:
AxiomLogGroupsListenerCloudTrail:
Type: AWS::CloudTrail::Trail
Condition: ShouldEnableCloudTrail
DependsOn: AxiomCloudWatchLogsSubscriberS3BucketPolicy
DependsOn: AxiomCloudWatchLogGroupsListenerS3BucketPolicy
Properties:
EnableLogFileValidation: false
IncludeGlobalServiceEvents: true
IsMultiRegionTrail: true
IsLogging: true
S3BucketName: !Ref AxiomCloudWatchLogsSubscriberS3Bucket
S3BucketName: !Ref AxiomCloudWatchLogGroupsListenerS3Bucket
TrailName: !Join ["-", [!Ref AWS::StackName, { "Ref": "AWS::AccountId" }]]
AxiomLogsSubscriberEventRule:
DependsOn: AxiomCloudWatchLogsSubscriber
AxiomLogGroupsListenerrEventRule:
DependsOn: AxiomCloudWatchLogGroupsListener
Type: AWS::Events::Rule
Properties:
Description: Axiom log group auto subscription event rule.,
Expand All @@ -100,8 +100,8 @@ Resources:
["-", [{ "Ref": "AWS::StackName" }, "auto-subscription-rule"]]
Targets:
- Id: !Join ["-", [!Ref "AWS::StackName", "auto-subscription-rule"]]
Arn: !GetAtt ["AxiomCloudWatchLogsSubscriber", "Arn"]
AxiomCloudWatchLogsSubscriberPolicy:
Arn: !GetAtt ["AxiomLogGroupsListener", "Arn"]
AxiomLogGroupsListenerrPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Expand All @@ -120,10 +120,10 @@ Resources:
- logs:GetLogEvents
Effect: Allow
Resource: "*"
PolicyName: cloudwatch-subscriber-axiom-policy
PolicyName: axiom-cloudwatch-log-groups-listener-policy
Roles:
- !Ref "AxiomCloudWatchLogsSubscriberRole"
AxiomCloudWatchLogsSubscriberRole:
- !Ref "AxiomCloudWatchLogGroupsListener"
AxiomCloudWatchLogGroupsListenerRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Expand All @@ -137,10 +137,10 @@ Resources:
- logs.amazonaws.com
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
AxiomCloudWatchLogsSubscriber:
AxiomCloudWatchLogGroupsListener:
Type: AWS::Lambda::Function
DependsOn:
- AxiomCloudWatchLogsSubscriberRole
- AxiomCloudWatchLogGroupsListenerRole
Properties:
FunctionName: !Ref LambdaFunctionName
Runtime: python3.9
Expand All @@ -150,27 +150,27 @@ Resources:
# DO NOT EDIT
# CI will replace these comments with the code from ./logs_subscriber.py
Role: !GetAtt
- AxiomCloudWatchLogsSubscriberRole
- AxiomCloudWatchLogGroupsListenerRole
- Arn
Description: Axiom CloudWatch Automatic Logs Subscriber Lambda
Description: Axiom CloudWatch Automatic log groups listener lambda
Environment:
Variables:
AXIOM_CLOUDWATCH_LAMBDA_INGESTER_ARN: !Ref "AxiomCloudWatchLambdaIngesterARN"
AXIOM_CLOUDWATCH_FORWARDER_LAMBDA_ARN: !Ref "AxiomCloudWatchForwarderLambdaARN"
LOG_GROUP_PREFIX: !Ref "CloudWatchLogGroupsPrefix"
AxiomCloudWatchLogsSubscriberPermission:
AxiomCloudWatchLogGroupsListenerPermission:
Type: AWS::Lambda::Permission
Properties:
Action: "lambda:InvokeFunction"
FunctionName: { "Fn::GetAtt": ["AxiomCloudWatchLogsSubscriber", "Arn"] }
FunctionName: { "Fn::GetAtt": ["AxiomCloudWatchLogGroupsListener", "Arn"] }
Principal: "events.amazonaws.com"
SourceAccount:
Ref: AWS::AccountId
SourceArn: !GetAtt ["AxiomLogsSubscriberEventRule", "Arn"]
SourceArn: !GetAtt ["AxiomCloudWatchLogGroupsListenerEventRule", "Arn"]
AxiomCloudWatchLogsSubscriberLogGroup:
DependsOn: ["AxiomCloudWatchLogsSubscriberRole"]
DependsOn: ["AxiomCloudWatchLogGroupsListenerRole"]
Type: AWS::Logs::LogGroup
Properties:
LogGroupName:
!Join ["", ["/aws/lambda/", { "Ref": "AxiomCloudWatchLogsSubscriber" }]]
!Join ["", ["/aws/lambda/", { "Ref": "AxiomCloudWatchLogGroupsListener" }]]
RetentionInDays:
Ref: "AxiomLambdaLogRetention"
8 changes: 4 additions & 4 deletions log_groups_listener.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# subscribe the Axiom ingester to newly created log groups
# Automatically subscribes the Axiom CloudWatch Forwarder to newly created log groups
import boto3
import os
import logging

# Set environment variables.
axiom_cloudwatch_lambda_ingester_arn = os.getenv("AXIOM_CLOUDWATCH_LAMBDA_INGESTER_ARN")
axiom_cloudwatch_forwarder_lambda_arn = os.getenv("AXIOM_CLOUDWATCH_FORWARDER_LAMBDA_ARN")
log_group_prefix = os.getenv("LOG_GROUP_PREFIX", "")

# set logger
Expand All @@ -20,7 +20,7 @@

def lambda_handler(event, context):
"""
Subscribes log ingester to log group from event.
Subscribes Axiom CloudWatch Forwarder to log group from event.
:param event: Event data from CloudWatch Logs.
:type event: dict
Expand All @@ -44,7 +44,7 @@ def lambda_handler(event, context):
# or whether the log group's name starts with the set prefix.
if not log_group_prefix or log_group_name.startswith(log_group_prefix):
create_subscription_filter(
log_group_name, log_group_arn, axiom_cloudwatch_lambda_ingester_arn
log_group_name, log_group_arn, axiom_cloudwatch_forwarder_lambda_arn
)

else:
Expand Down

0 comments on commit c0505ad

Please sign in to comment.