Skip to content

Commit 41e2348

Browse files
authored
Merge pull request #79 from SumoLogic/hpal_bucket_fix
Fixing Region bucket mapping
2 parents aa3457b + ae0d628 commit 41e2348

File tree

13 files changed

+439
-160
lines changed

13 files changed

+439
-160
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ jobs:
1010
env: FUNCTION_DIR=cloudwatchlogs-with-dlq TEST_FILE=test_cwl_lambda.py NODE_VERSION="8.10"
1111
- stage: Node 8
1212
node_js: '8.10'
13-
env: FUNCTION_DIR=loggroup-lambda-connector TEST_FILE=test_loggroup_lambda_connector.py NODE_VERSION="8.10"
13+
env: FUNCTION_DIR=loggroup-lambda-connector/test TEST_FILE=test_loggroup_lambda_connector.py NODE_VERSION="8.10"
1414
- stage: Node 6
1515
node_js: '6.10'
1616
env: FUNCTION_DIR=cloudwatchlogs-with-dlq TEST_FILE=test_cwl_lambda.py NODE_VERSION="6.10"
1717
- stage: Node 6
1818
node_js: '6.10'
19-
env: FUNCTION_DIR=loggroup-lambda-connector TEST_FILE=test_loggroup_lambda_connector.py NODE_VERSION="6.10"
19+
env: FUNCTION_DIR=loggroup-lambda-connector/test TEST_FILE=test_loggroup_lambda_connector.py NODE_VERSION="6.10"
2020
before_install:
2121
- sudo apt-get install python-pip
2222
- cd $FUNCTION_DIR

cloudwatchlogs-with-dlq/DLQLambdaCloudFormation.json

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@
3030
"Description": "Select true to get loggroup/logstream values in logs"
3131
}
3232
},
33+
"Mappings" : {
34+
"RegionMap" : {
35+
"us-east-1": {"bucketname": "appdevzipfiles-us-east-1"},
36+
"us-east-2": {"bucketname": "appdevzipfiles-us-east-2"},
37+
"us-west-1": {"bucketname": "appdevzipfiles-us-west-1"},
38+
"us-west-2": {"bucketname": "appdevzipfiles-us-west-2"},
39+
"ap-south-1": {"bucketname": "appdevzipfiles-ap-south-1"},
40+
"ap-northeast-2": {"bucketname": "appdevzipfiles-ap-northeast-2"},
41+
"ap-southeast-1": {"bucketname": "appdevzipfiles-ap-southeast-1"},
42+
"ap-southeast-2": {"bucketname": "appdevzipfiles-ap-southeast-2"},
43+
"ap-northeast-1": {"bucketname": "appdevzipfiles-ap-northeast-1"},
44+
"ca-central-1": {"bucketname": "appdevzipfiles-ca-central-1"},
45+
"eu-central-1": {"bucketname": "appdevzipfiles-eu-central-1"},
46+
"eu-west-1": {"bucketname": "appdevzipfiles-eu-west-1"},
47+
"eu-west-2": {"bucketname": "appdevzipfiles-eu-west-2"},
48+
"eu-west-3": {"bucketname": "appdevzipfiles-eu-west-3"},
49+
"sa-east-1": {"bucketname": "appdevzipfiles-sa-east-1"}
50+
}
51+
},
3352
"Resources": {
3453
"SumoCWLogGroup": {
3554
"Type": "AWS::Logs::LogGroup",
@@ -176,7 +195,7 @@
176195
"Properties": {
177196
"FunctionName": { "Fn::Join": [ "-", [ "SumoCWLogsLambda", { "Fn::Select" : [ "2", {"Fn::Split" : [ "/" , { "Ref": "AWS::StackId" } ]}] } ] ] },
178197
"Code": {
179-
"S3Bucket": {"Fn::Join": ["", ["appdevzipfiles-", { "Ref" : "AWS::Region" }] ] },
198+
"S3Bucket": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "bucketname"]},
180199
"S3Key": "cloudwatchlogs-with-dlq.zip"
181200
},
182201
"Role": {
@@ -237,7 +256,7 @@
237256
"Properties": {
238257
"FunctionName": { "Fn::Join": [ "-", [ "SumoCWProcessDLQLambda", { "Fn::Select" : [ "2", {"Fn::Split" : [ "/" , { "Ref": "AWS::StackId" } ]}] } ] ] },
239258
"Code": {
240-
"S3Bucket": {"Fn::Join": ["", ["appdevzipfiles-", { "Ref" : "AWS::Region" }] ] },
259+
"S3Bucket": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "bucketname"]},
241260
"S3Key": "cloudwatchlogs-with-dlq.zip"
242261
},
243262
"Role": {
@@ -321,7 +340,8 @@
321340
"Description": "The ARN of the sumologic cloudwatch logs lambda",
322341
"Value" : { "Fn::GetAtt" : ["SumoCWLogsLambda", "Arn"] },
323342
"Export" : {
324-
"Name" : "SumoCWLogsLambdaArn"
343+
"Name" : { "Fn::Join": [ "-", [ "SumoCWLogsLambdaArn", { "Fn::Select" : [ "2", {"Fn::Split" : [ "/" , { "Ref": "AWS::StackId" } ]}] } ] ] }
344+
325345
}
326346
}
327347
}

loggroup-lambda-connector/Readme.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
# LogGroup Lambda Connector
1+
# SumoLogic LogGroup Connector
22
This is used to automatically subscribe newly created and existing Cloudwatch LogGroups to a Lambda function.
33

4-
### Creating Stack in AWS Cloudformation
5-
you can create the stack by using [aws-cli](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-cli-creating-stack.html) or directly from aws console using webbrowser and uploading loggroup-lambda-cft.json. For more details checkout it's [documentation](https://help.sumologic.com/?cid=39393)
4+
Made with ❤️ by Sumo Logic. Available on the [AWS Serverless Application Repository](https://aws.amazon.com/serverless)
5+
6+
### Deploying the SAM Application
7+
1. Open a browser window and enter the following URL: https://serverlessrepo.aws.amazon.com/applications
8+
2. In the Serverless Application Repository, search for sumologic.
9+
3. Select Show apps that create custom IAM roles or resource policies check box.
10+
4. Click the sumologic-loggroup-connector,link, and then click Deploy.
11+
5. In the Configure application parameters panel,
12+
LambdaARN: "Enter ARN for target lambda function" All loggroups matching the pattern are subscribed to this function
13+
LogGroupPattern: "Enter regex for matching logGroups"
14+
UseExistingLogs: "Select true for subscribing existing logs"
15+
6. Click Deploy.
16+
617

718
### Configuring Lambda
819
It has two environment variables
@@ -28,6 +39,8 @@ It has two environment variables
2839
]
2940
]
3041
}
42+
43+
**USE_EXISTING_LOGS**: This is used for subscribing existing log groups. By setting this parameter to true and invoking the function manually, all the existing log groups matching the pattern will be subscribed to lambda function with LAMBDA_ARN as arn
3144
```
3245

3346
### For Developers
@@ -50,4 +63,12 @@ Running the test cases
5063
```
5164
Run the above command after building the zip file
5265

66+
## License
67+
68+
Apache License 2.0 (Apache-2.0)
69+
70+
71+
## Support
72+
Requests & issues should be filed on GitHub: https://github.com/SumoLogic/sumologic-aws-lambda/issues
73+
5374

loggroup-lambda-connector/loggroup-lambda-cft.json

Lines changed: 0 additions & 127 deletions
This file was deleted.

loggroup-lambda-connector/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"devDependencies": {},
1010
"scripts": {
1111
"test": "echo \"Error: no test specified\" && exit 1",
12-
"build": "rm -f loggroup-lambda-connector.zip && zip -r loggroup-lambda-connector.zip loggroup-lambda-connector.js package.json",
13-
"prod_deploy": "python -c 'from test_loggroup_lambda_connector import prod_deploy;prod_deploy()'"
12+
"build": "echo `pwd` && rm -f test/loggroup-lambda-connector.zip && zip -r test/loggroup-lambda-connector.zip src/loggroup-lambda-connector.js package.json",
13+
"prod_deploy": "python -c 'from test.test_loggroup_lambda_connector import prod_deploy;prod_deploy()'"
1414
},
1515
"keywords": [
1616
"AWS"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Description: '"Lambda Function for automatic subscription of any Sumo Logic lambda
3+
function with loggroups matching an input pattern."
4+
5+
'
6+
Globals:
7+
Function:
8+
MemorySize: 128
9+
Timeout: 300
10+
Outputs:
11+
SumoLogGroupLambdaConnector:
12+
Description: SumoLogGroupLambdaConnector Function ARN
13+
Value:
14+
Fn::GetAtt:
15+
- SumoLogGroupLambdaConnector
16+
- Arn
17+
Parameters:
18+
LambdaARN:
19+
Default: arn:aws:lambda:us-east-1:123456789000:function:TestLambda
20+
Description: Enter ARN for target lambda function
21+
Type: String
22+
LogGroupPattern:
23+
Default: Test
24+
Description: Enter regex for matching logGroups
25+
Type: String
26+
UseExistingLogs:
27+
AllowedValues:
28+
- 'true'
29+
- 'false'
30+
Default: 'false'
31+
Description: Select true for subscribing existing logs
32+
Type: String
33+
Resources:
34+
SumoCWLambdaInvokePermission:
35+
Properties:
36+
Action: lambda:InvokeFunction
37+
FunctionName:
38+
Ref: LambdaARN
39+
Principal:
40+
Fn::Sub: logs.${AWS::Region}.amazonaws.com
41+
SourceAccount:
42+
Ref: AWS::AccountId
43+
SourceArn:
44+
Fn::Sub: arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:*:*
45+
Type: AWS::Lambda::Permission
46+
SumoLogGroupLambdaConnector:
47+
Properties:
48+
CodeUri: s3://appdevstore/6bef113d950a9923b446dd438116f2a1
49+
Environment:
50+
Variables:
51+
LAMBDA_ARN:
52+
Ref: LambdaARN
53+
LOG_GROUP_PATTERN:
54+
Ref: LogGroupPattern
55+
USE_EXISTING_LOG_GROUPS:
56+
Ref: UseExistingLogs
57+
Events:
58+
LambdaTrigger:
59+
Properties:
60+
Pattern:
61+
detail:
62+
eventName:
63+
- CreateLogGroup
64+
eventSource:
65+
- logs.amazonaws.com
66+
source:
67+
- aws.logs
68+
Type: CloudWatchEvent
69+
Handler: loggroup-lambda-connector.handler
70+
Policies:
71+
- Statement:
72+
- Action:
73+
- logs:DescribeLogGroups
74+
- logs:DescribeLogStreams
75+
- logs:PutSubscriptionFilter
76+
Effect: Allow
77+
Resource:
78+
- Fn::Sub: arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:*
79+
Sid: ReadWriteFilterPolicy
80+
Runtime: nodejs8.10
81+
Type: AWS::Serverless::Function
82+
Transform: AWS::Serverless-2016-10-31
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
if [ "$AWS_PROFILE" == "prod" ]
4+
then
5+
SAM_S3_BUCKET="appdevstore"
6+
AWS_REGION="us-east-1"
7+
else
8+
SAM_S3_BUCKET="cf-templates-5d0x5unchag-us-east-2"
9+
AWS_REGION="us-east-2"
10+
fi
11+
sam package --template-file template.yaml --s3-bucket $SAM_S3_BUCKET --output-template-file packaged.yaml
12+
13+
sam deploy --template-file packaged.yaml --stack-name testingloggrpconnector --capabilities CAPABILITY_IAM --region $AWS_REGION --parameter-overrides LambdaARN="arn:aws:lambda:us-east-1:956882708938:function:AccessVPCResourcesLambda"
14+
#aws cloudformation describe-stack-events --stack-name testingloggrpconnector --region $AWS_REGION
15+
#aws cloudformation get-template --stack-name testingloggrpconnector --region $AWS_REGION
16+
# aws serverlessrepo create-application-version --region us-east-1 --application-id arn:aws:serverlessrepo:us-east-1:$AWS_ACCOUNT_ID:applications/sumologic-securityhub-connector --semantic-version 1.0.1 --template-body file://packaged.yaml

0 commit comments

Comments
 (0)