Skip to content

Commit 84791af

Browse files
authored
Merge pull request #7 from framer/wip/merge-and-improve
Merge upstream improvements
2 parents ee86d92 + ef2fb53 commit 84791af

File tree

10 files changed

+424
-98
lines changed

10 files changed

+424
-98
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ packaged.yml
2727
# SAM
2828
.aws-sam/
2929
#VS Code
30-
.vscode/
30+
.vscode/
31+
#JetBrains
32+
.idea

DEVELOPER.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Developer
2+
3+
This project uses [SAM](https://aws.amazon.com/serverless/sam/) tool for build,
4+
run locally, package and publish.
5+
6+
There is a serverless file to play locally as well, but here we will focus on
7+
the [SAM](https://aws.amazon.com/serverless/sam/) way of doing it.
8+
9+
## Requirements
10+
11+
- Make
12+
13+
### Local run / build
14+
15+
- Docker
16+
- AWS Account
17+
- AWS Profile configured on your computer, remember that AWS uses the `default`
18+
profile unless you specify it. You can specify usign `AWS_PROFILE` enviroment
19+
variable.
20+
- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html#serverless-sam-cli)
21+
22+
### Package
23+
24+
- An AWS S3 bucket where the package will be uploaded
25+
26+
### Deploy
27+
28+
- AWS Account and enough permissions to do the deploy, generated template will
29+
need IAM capabilities.
30+
31+
### Publishing
32+
33+
- For personal publishing is mandatory to update the function name on the
34+
`template.yml` file to avoid collide with the New Relic official release of
35+
this application.
36+
37+
## Building it locally
38+
39+
This will generate an image of the lambda application using a docker container
40+
that you will be able to run locally.
41+
42+
Just run `make build`.
43+
44+
## Running locally
45+
46+
You should have built the image locally as mentioned in the previous step.
47+
48+
Then you need to have a "sample" event of a file in an S3 bucket so we can use
49+
it, we provide a sample one in the test/mock.json but it wouldn't work if you
50+
haven't access to the given S3 bucket.
51+
52+
Then just run `LICENSE_KEY=<YOUR_NEW_RELIC_LICENSE_KEY> TEST_FILE="./test/mock.json" make run` to run it locally.
53+
54+
## Packaging
55+
56+
Run `BUCKET=<S3_BUCKET_NAME> REGION=<S3_BUCKET_AWS_REGION> make package`
57+
58+
## Deploying
59+
60+
Run `REGION=<THE_REGION_YOU_WANT> STACK_NAME=<THE_STACK_NAME_YOU_WANT> make deploy`
61+
62+
## Publishing
63+
64+
Run `REGION=<SAR_AWS_REGION> make publish` to publish your package. Remember to
65+
update the function name before publishing it to do not collide with the New
66+
Relic official application.

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
build:
2+
sam build --use-container
3+
4+
run: check-run-env
5+
sam local invoke "NewRelicLogIngestionFunction" -e $(TEST_FILE)
6+
7+
package: check-package-env
8+
sam package --output-template-file packaged.yml --s3-bucket $(BUCKET) --region $(REGION)
9+
10+
deploy: check-deploy-env
11+
sam deploy --template-file packaged.yml --stack-name $(STACK_NAME) --region $(REGION)
12+
13+
publish: check-publish-env
14+
sam publish --template packaged.yml --region $(REGION)
15+
16+
check-run-env:
17+
ifndef LICENSE_KEY
18+
$(error LICENSE_KEY is undefined)
19+
endif
20+
ifndef TEST_FILE
21+
$(error TEST_FILE is undefined)
22+
endif
23+
24+
check-package-env:
25+
ifndef REGION
26+
$(error REGION is undefined)
27+
endif
28+
ifndef BUCKET
29+
$(error BUCKET is undefined)
30+
endif
31+
32+
check-deploy-env:
33+
ifndef REGION
34+
$(error REGION is undefined)
35+
endif
36+
ifndef STACK_NAME
37+
$(error STACK_NAME is undefined)
38+
endif
39+
40+
check-publish-env:
41+
ifndef REGION
42+
$(error REGION is undefined)
43+
endif

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Community Project header](https://github.com/newrelic/open-source-office/raw/master/examples/categories/images/Community_Project.png)](https://github.com/newrelic/open-source-office/blob/master/examples/categories/index.md#community-project)
1+
[![Community Plus header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Plus.png)](https://opensource.newrelic.com/oss-category/#community-plus)
22

33
# AWS Lambda for sending logs from S3 to New Relic
44

@@ -22,5 +22,11 @@ Contributions to improve s3-log-ingestion-lambda are encouraged! Keep in mind wh
2222

2323
To execute our corporate CLA, which is required if your contribution is on behalf of a company, or if you have any questions, please drop us an email at [email protected].
2424

25+
## Developers
26+
27+
For more information about how to contribute from the developer point of view,
28+
we recommend you to take a look to the [DEVELOPER.md](./DEVELOPER.md) that
29+
contains most of the info you'll need.
30+
2531
## License
26-
`s3-log-ingestion-lambda` is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License. The s3-log-ingestion-lambda also uses source code from third party libraries. Full details on which libraries are used and the terms under which they are licensed can be found in the third party notices docume
32+
`s3-log-ingestion-lambda` is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License. The s3-log-ingestion-lambda also uses source code from third party libraries. Full details on which libraries are used and the terms under which they are licensed can be found in the third party notices document

requirements.txt

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

serverless.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,37 @@ service: ${env:SERVICE_NAME}
2222

2323
provider:
2424
name: aws
25-
runtime: python3.8
25+
runtime: python3.11
2626
iamRoleStatements:
2727
- Effect: "Allow"
2828
Action:
29-
- "s3:GetObject"
29+
- "s3:GetObject"
3030
Resource: "arn:aws:s3:::${env:S3_BUCKET_NAME}/*"
3131

3232
plugins:
3333
- serverless-python-requirements
34-
34+
3535
custom:
3636
pythonRequirements:
37+
fileName: ./src/requirements.txt
3738
dockerizePip: non-linux
3839

3940
functions:
4041
NewRelic-s3-log-ingestion:
4142
handler: src/handler.lambda_handler
42-
environment:
43+
environment:
4344
LICENSE_KEY: ${env:LICENSE_KEY}
4445
LOG_TYPE: ${env:LOG_TYPE}
4546
DEBUG_ENABLED: ${env:DEBUG_ENABLED}
47+
S3_CLOUD_TRAIL_LOG_PATTERN: ${env:S3_CLOUD_TRAIL_LOG_PATTERN}
48+
S3_IGNORE_PATTERN: ${env:S3_IGNORE_PATTERN}
49+
BATCH_SIZE_FACTOR: ${env:BATCH_SIZE_FACTOR}
50+
ADDITIONAL_ATTRIBUTES: ${env:ADDITIONAL_ATTRIBUTES}
51+
4652
events:
4753
- s3:
4854
bucket: ${env:S3_BUCKET_NAME}
4955
event: s3:ObjectCreated:*
5056
rules:
5157
- prefix: ${env:S3_PREFIX, ""}
52-
existing: true
58+
existing: true

0 commit comments

Comments
 (0)