Skip to content
Permalink
Browse files

add stubbed log analyzer func

  • Loading branch information...
ThatJoeMoore committed Jul 2, 2018
1 parent 06d2537 commit 1612b752a5077ea943c9f58b0f1d73d070f73121
@@ -364,6 +364,36 @@ Resources:
Properties:
FunctionName: !Ref EnhancedHeadersFunc

LogAnalyzerSorterFunc:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "${CDNName}-LogAnalyzer-Sorter"
CodeUri: ./../log-analyzer/sorter-lambda/
Handler: lib/lambda.handler
Runtime: nodejs8.10
MemorySize: 128
Timeout: 20
Role:
Fn::ImportValue: !Sub "${AccountStackName}-EdgeLambdaExecutionRole"
Events:
s3log:
Type: S3
Properties:
Bucket:
Fn::ImportValue: !Sub "${AccountStackName}-InfraAndLogBucket"
Events: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- Name: prefix
Value:
Fn::Sub:
- "${Logs}/${Env}/${DNS}"
- Logs:
Fn::ImportValue: !Sub "${AccountStackName}-InfraBucketLogsPrefix"
Env: !Ref Environment
DNS: !Ref RootDNS

Outputs:
ContentBucket:
Value: !Ref CdnContentBucket
@@ -3,7 +3,8 @@
"packages": [
"assembler",
"edge-lambdas/*",
"webhooks"
"webhooks",
"log-analyzer/sorter-lambda"
],
"version": "1.0.0",
"npmClient": "yarn",
File renamed without changes.
@@ -0,0 +1,2 @@
lib/

@@ -0,0 +1,7 @@
#!/bin/sh

echo "=========== Building Sorter Lambda ==========="

set -e

yarn build
@@ -0,0 +1,33 @@
{
"name": "web-community-log-sorter-lambda",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"test": "mocha --recursive",
"cli": "ts-node src/cli.ts"
},
"engines": {
"node": ">=8.0.0",
"npm": ">=5.0.0"
},
"author": "",
"license": "Apache-2.0",
"dependencies": {
"aws-sdk": "^2.89.0",
"luxon": "^1.3.0",
"split2": "^2.2.0",
"string-to-stream": "^1.1.1",
"through2": "^2.0.3"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.7",
"@types/luxon": "^1.2.0",
"@types/node": "^10.3.6",
"@types/split2": "^2.1.6",
"@types/through2": "^2.0.33",
"ts-node": "^7.0.0",
"typescript": "^2.9.2"
}
}
@@ -0,0 +1,86 @@
/*
* @license
* Copyright 2018 Brigham Young University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { S3Event } from 'aws-lambda';
import {S3} from 'aws-sdk';

export async function handler(event: S3Event) {
console.log('event:', JSON.stringify(event, null, 2));
// for (const record of event.Records) {
//
// }
console.log('Done');
}

/*
Test Message
{
"Service":"Amazon S3",
"Event":"s3:TestEvent",
"Time":"2014-10-13T15:57:02.089Z",
"Bucket":"bucketname",
"RequestId":"5582815E1AEA5ADF",
"HostId":"8cLeGAmw098X5cv4Zkwcmo8vvZa3eH3eKxsPzbB9wrR+YstdA6Knx4Ip8EXAMPLE"
}
*/
/*
PUT Object
{
"Records":[
{
"eventVersion":"2.0",
"eventSource":"aws:s3",
"awsRegion":"us-east-1",
"eventTime":"1970-01-01T00:00:00.000Z",
"eventName":"ObjectCreated:Put",
"userIdentity":{
"principalId":"AIDAJDPLRKLG7UEXAMPLE"
},
"requestParameters":{
"sourceIPAddress":"127.0.0.1"
},
"responseElements":{
"x-amz-request-id":"C3D13FE58DE4C810",
"x-amz-id-2":"FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD"
},
"s3":{
"s3SchemaVersion":"1.0",
"configurationId":"testConfigRule",
"bucket":{
"name":"mybucket",
"ownerIdentity":{
"principalId":"A3NL1KOZZKExample"
},
"arn":"arn:aws:s3:::mybucket"
},
"object":{
"key":"HappyFace.jpg",
"size":1024,
"eTag":"d41d8cd98f00b204e9800998ecf8427e",
"versionId":"096fKKXTRTtl3on89fVO.nfljtsv6qko",
"sequencer":"0055AED6DCD90281E5"
}
}
}
]
}
*/

@@ -0,0 +1,14 @@
{
"include": ["./src/**/*"],
"compilerOptions": {
"target": "es2017",
"lib": ["es2017"],
"module": "commonjs",
"allowJs": true,
"checkJs": false,
"outDir": "./lib",
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true
}
}

0 comments on commit 1612b75

Please sign in to comment.
You can’t perform that action at this time.