Skip to content

Commit

Permalink
Merge pull request #7 from framer/wip/merge-and-improve
Browse files Browse the repository at this point in the history
Merge upstream improvements
  • Loading branch information
ankon authored Aug 2, 2024
2 parents ee86d92 + ef2fb53 commit 84791af
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 98 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ packaged.yml
# SAM
.aws-sam/
#VS Code
.vscode/
.vscode/
#JetBrains
.idea
66 changes: 66 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Developer

This project uses [SAM](https://aws.amazon.com/serverless/sam/) tool for build,
run locally, package and publish.

There is a serverless file to play locally as well, but here we will focus on
the [SAM](https://aws.amazon.com/serverless/sam/) way of doing it.

## Requirements

- Make

### Local run / build

- Docker
- AWS Account
- AWS Profile configured on your computer, remember that AWS uses the `default`
profile unless you specify it. You can specify usign `AWS_PROFILE` enviroment
variable.
- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html#serverless-sam-cli)

### Package

- An AWS S3 bucket where the package will be uploaded

### Deploy

- AWS Account and enough permissions to do the deploy, generated template will
need IAM capabilities.

### Publishing

- For personal publishing is mandatory to update the function name on the
`template.yml` file to avoid collide with the New Relic official release of
this application.

## Building it locally

This will generate an image of the lambda application using a docker container
that you will be able to run locally.

Just run `make build`.

## Running locally

You should have built the image locally as mentioned in the previous step.

Then you need to have a "sample" event of a file in an S3 bucket so we can use
it, we provide a sample one in the test/mock.json but it wouldn't work if you
haven't access to the given S3 bucket.

Then just run `LICENSE_KEY=<YOUR_NEW_RELIC_LICENSE_KEY> TEST_FILE="./test/mock.json" make run` to run it locally.

## Packaging

Run `BUCKET=<S3_BUCKET_NAME> REGION=<S3_BUCKET_AWS_REGION> make package`

## Deploying

Run `REGION=<THE_REGION_YOU_WANT> STACK_NAME=<THE_STACK_NAME_YOU_WANT> make deploy`

## Publishing

Run `REGION=<SAR_AWS_REGION> make publish` to publish your package. Remember to
update the function name before publishing it to do not collide with the New
Relic official application.
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
build:
sam build --use-container

run: check-run-env
sam local invoke "NewRelicLogIngestionFunction" -e $(TEST_FILE)

package: check-package-env
sam package --output-template-file packaged.yml --s3-bucket $(BUCKET) --region $(REGION)

deploy: check-deploy-env
sam deploy --template-file packaged.yml --stack-name $(STACK_NAME) --region $(REGION)

publish: check-publish-env
sam publish --template packaged.yml --region $(REGION)

check-run-env:
ifndef LICENSE_KEY
$(error LICENSE_KEY is undefined)
endif
ifndef TEST_FILE
$(error TEST_FILE is undefined)
endif

check-package-env:
ifndef REGION
$(error REGION is undefined)
endif
ifndef BUCKET
$(error BUCKET is undefined)
endif

check-deploy-env:
ifndef REGION
$(error REGION is undefined)
endif
ifndef STACK_NAME
$(error STACK_NAME is undefined)
endif

check-publish-env:
ifndef REGION
$(error REGION is undefined)
endif
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![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)
[![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)

# AWS Lambda for sending logs from S3 to New Relic

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

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].

## Developers

For more information about how to contribute from the developer point of view,
we recommend you to take a look to the [DEVELOPER.md](./DEVELOPER.md) that
contains most of the info you'll need.

## License
`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
`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
21 changes: 0 additions & 21 deletions requirements.txt

This file was deleted.

16 changes: 11 additions & 5 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,37 @@ service: ${env:SERVICE_NAME}

provider:
name: aws
runtime: python3.8
runtime: python3.11
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:GetObject"
- "s3:GetObject"
Resource: "arn:aws:s3:::${env:S3_BUCKET_NAME}/*"

plugins:
- serverless-python-requirements

custom:
pythonRequirements:
fileName: ./src/requirements.txt
dockerizePip: non-linux

functions:
NewRelic-s3-log-ingestion:
handler: src/handler.lambda_handler
environment:
environment:
LICENSE_KEY: ${env:LICENSE_KEY}
LOG_TYPE: ${env:LOG_TYPE}
DEBUG_ENABLED: ${env:DEBUG_ENABLED}
S3_CLOUD_TRAIL_LOG_PATTERN: ${env:S3_CLOUD_TRAIL_LOG_PATTERN}
S3_IGNORE_PATTERN: ${env:S3_IGNORE_PATTERN}
BATCH_SIZE_FACTOR: ${env:BATCH_SIZE_FACTOR}
ADDITIONAL_ATTRIBUTES: ${env:ADDITIONAL_ATTRIBUTES}

events:
- s3:
bucket: ${env:S3_BUCKET_NAME}
event: s3:ObjectCreated:*
rules:
- prefix: ${env:S3_PREFIX, ""}
existing: true
existing: true
Loading

0 comments on commit 84791af

Please sign in to comment.