Skip to content

Commit 6686ed6

Browse files
committed
Initial commit
0 parents  commit 6686ed6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+5518
-0
lines changed

.github/workflows/pull_request.yaml

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Pull Request Workflow
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
validate-template-code:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Install AWS SAM CLI
16+
run: |
17+
pip install aws-sam-cli
18+
19+
- name: Install golint
20+
run: |
21+
go install golang.org/x/lint/golint@latest
22+
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
23+
24+
- name: Lint Go Code
25+
run: |
26+
# Find all .go files, excluding the vendor directory
27+
go_files=$(find . -name "*.go" -not -path "./vendor/*" -not -path "./src/vendor/*")
28+
29+
# Run golint on each Go file
30+
lint_output=""
31+
for file in $go_files; do
32+
output=$(golint $file)
33+
if [ -n "$output" ]; then
34+
lint_output="$lint_output\n$output"
35+
fi
36+
done
37+
38+
if [ -n "$lint_output" ]; then
39+
echo "Linting issues found:"
40+
echo -e "$lint_output"
41+
exit 1
42+
else
43+
echo "No linting issues found."
44+
fi
45+
- name: Run gofmt
46+
run: |
47+
# Find all .go files and check if they are properly formatted
48+
unformatted=$(gofmt -l $(find . -name "*.go" -not -path "./src/vendor/*"))
49+
if [ -n "$unformatted" ]; then
50+
echo "The following files are not formatted:"
51+
echo "$unformatted"
52+
exit 1
53+
else
54+
echo "All files are properly formatted."
55+
fi
56+
57+
- name: Validate SAM Templates
58+
run: |
59+
for template in $(find . -name ".yaml" -o -name ".yml"); do
60+
echo "Validating template: $template"
61+
sam validate --template-file "$template" --region us-east-2 --lint
62+
done
63+
security:
64+
runs-on: ubuntu-latest
65+
66+
steps:
67+
- name: Checkout code
68+
uses: actions/checkout@v4
69+
- name: Run CFN Nag Security Checks
70+
uses: stelligent/cfn_nag@master
71+
with:
72+
input_path: .
73+
extra_args: -o sarif
74+
output_path: cfn_nag.sarif
75+
- name: Upload CFN Nag SARIF
76+
uses: github/codeql-action/upload-sarif@v3
77+
with:
78+
sarif_file: cfn_nag.sarif
79+
category: security
80+
81+
trivy-scan:
82+
name: Trivy security scan
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Checkout code
86+
uses: actions/checkout@v4
87+
88+
- name: Run Trivy vulnerability scanner in repo mode for Low Priority
89+
uses: aquasecurity/trivy-action@master
90+
with:
91+
scan-type: fs
92+
ignore-unfixed: true
93+
severity: 'LOW,MEDIUM'
94+
env:
95+
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db
96+
TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db
97+
- name: Run Trivy vulnerability scanner in repo mode for High Priority
98+
uses: aquasecurity/trivy-action@master
99+
with:
100+
scan-type: fs
101+
ignore-unfixed: true
102+
exit-code: 1
103+
severity: 'HIGH,CRITICAL'
104+
env:
105+
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db
106+
TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db
107+
108+
test-and-coverage:
109+
runs-on: ubuntu-latest
110+
steps:
111+
- name: Checkout code
112+
uses: actions/checkout@v4
113+
114+
- name: Setup Go
115+
uses: actions/setup-go@v5
116+
with:
117+
go-version: '1.22'
118+
#scripts to include the integration and end to end tests should be added here
119+
- name: Run Test Cases and Coverage
120+
run: |
121+
cd src
122+
mkdir -p coverage
123+
go test -race -coverprofile=coverage/coverage.out ./...
124+
go tool cover -html=coverage/coverage.out -o coverage/coverage.html
125+
126+
- name: Upload Coverage Report
127+
uses: actions/upload-artifact@v3
128+
with:
129+
name: coverage-report
130+
path: src/coverage/coverage.html

.github/workflows/release.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build and Deploy Lambda
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write
13+
contents: write
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: '1.22'
22+
23+
- name: Configure AWS Credentials
24+
uses: aws-actions/configure-aws-credentials@v3
25+
with:
26+
role-to-assume: ${{ secrets.AWS_SAR_PUBLISHER_ROLE }}
27+
aws-region: us-east-2
28+
29+
- name: Install AWS SAM CLI
30+
run: |
31+
pip install aws-sam-cli
32+
33+
- name: Build SAM Application
34+
run: sam build --template-file template.yaml --region us-east-2
35+
36+
- name: Package SAM Application
37+
run: sam package --s3-bucket unified-lambda-cft-1 --output-template-file packaged.yaml --region us-east-2
38+
# should we include retries as part of uploading?
39+
- name: Upload CloudFormation Template to S3
40+
run: aws s3 cp packaged.yaml s3://unified-lambda-serverless-1/packaged.yaml

.github/workflows/trivy_schedule.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Security Scan
2+
3+
on:
4+
schedule:
5+
# Run every day at 12 AM IST (which is 6:30 PM UTC)
6+
- cron: "30 18 * * *"
7+
8+
jobs:
9+
trivy:
10+
name: Trivy security scan
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Run Trivy vulnerability scanner sarif output
17+
uses: aquasecurity/trivy-action@master
18+
with:
19+
scan-type: fs
20+
ignore-unfixed: true
21+
severity: 'HIGH,CRITICAL'
22+
format: 'template'
23+
template: '@/contrib/sarif.tpl'
24+
output: 'trivy-results.sarif'
25+
exit : 1
26+
env:
27+
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db
28+
TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db
29+
30+
- name: Upload Trivy scan results to GitHub Security tab
31+
uses: github/codeql-action/upload-sarif@v3
32+
if: always()
33+
with:
34+
sarif_file: 'trivy-results.sarif'

.gitignore

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.DS_Store
2+
3+
# Created by https://www.toptal.com/developers/gitignore/api/sam+config,go
4+
# Edit at https://www.toptal.com/developers/gitignore?templates=sam+config,go
5+
6+
### Go ###
7+
# If you prefer the allow list template instead of the deny list, see community template:
8+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
9+
#
10+
# Binaries for programs and plugins
11+
*.exe
12+
*.exe~
13+
*.dll
14+
*.so
15+
*.dylib
16+
17+
# Test binary, built with `go test -c`
18+
*.test
19+
20+
# Output of the go coverage tool, specifically when used with LiteIDE
21+
*.out
22+
23+
# Dependency directories (remove the comment below to include it)
24+
# vendor/
25+
26+
# Go workspace file
27+
go.work
28+
29+
### SAM+config ###
30+
# Ignore build directories for the AWS Serverless Application Model (SAM)
31+
# Info: https://aws.amazon.com/serverless/sam/
32+
# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html
33+
34+
**/.aws-sam
35+
36+
### SAM+config Patch ###
37+
# SAM config - exclude this file if sharing publicly
38+
samconfig.toml
39+
40+
# End of https://www.toptal.com/developers/gitignore/api/sam+config,go
41+
42+
src/newrelic-aws-serverless-log-forwarding
43+
vendor/
44+
# updated dinamically
45+
test_events/cloud_watch/event.json
46+
47+
# created by aws sam
48+
packaged.yml
49+
50+
# integration test keys and secrets
51+
*.env

DEVELOPER.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Implementation
2+
3+
The Lambda leverages the [New Relic Go client](https://github.com/newrelic/newrelic-client-go) to process the logs in batches. This means it converts the AWS source logs into [detailed JSON format](https://docs.newrelic.com/docs/logs/log-api/introduction-log-api/#detailed-json).
4+
5+
## Requirements
6+
7+
- AWS CLI must be installed and configured with Administrator permission
8+
- Docker must be installed. Refer [Docker documentation.](https://www.docker.com/community-edition)
9+
- Golang must be installed. Refer [Golang documentation](https://golang.org)
10+
- Install the AWS SAM CLI. Refer [SAM CLI Documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
11+
12+
13+
## Unit Testing and Coverage
14+
15+
Run the following commands to:
16+
17+
- Run the unit tests:
18+
19+
```shell
20+
make test
21+
```
22+
23+
- Check the coverage:
24+
25+
```shell
26+
make coverage
27+
```

0 commit comments

Comments
 (0)