Skip to content

Commit

Permalink
Enhance Subscription Filter with Lambda Function Separation (#14)
Browse files Browse the repository at this point in the history
* Split Lambda function for EventBridge and CFN events

* update mod.go name and remove comments

* update workflow and readme
  • Loading branch information
bardabun authored Mar 31, 2024
1 parent 4a131cd commit c8c438d
Show file tree
Hide file tree
Showing 12 changed files with 855 additions and 405 deletions.
98 changes: 82 additions & 16 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,73 @@ on:
types: [published]

jobs:
build_function:
build_functions:
name: Build function
runs-on: ubuntu-latest
steps:
# Check out the repository to the runner
- name: Check out the repo
uses: actions/checkout@v3
- run: git fetch --force --tags

# Fetch all history for all tags and branches
- run: git fetch --prune --unshallow

# Setup Go environment
- uses: actions/setup-go@v3
with:
go-version: '1.19'

# Import GPG key for GoReleaser
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v4
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --rm-dist
args: release --clean
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build CloudFormation Lambda function
run: |
cd cfn-lambda
cp -R ../common ./common
GOOS=linux GOARCH=amd64 go build -o bootstrap .
zip -r ../cfn-lambda.zip .
cd ..
- name: Build and Zip EventBridge Lambda function with common dependencies
run: |
cd eventbridge-lambda
cp -R ../common ./common
GOOS=linux GOARCH=amd64 go build -o bootstrap .
zip -r ../eventbridge-lambda.zip .
cd ..
- name: Upload Lambdas ZIP as Artifact
uses: actions/upload-artifact@v2
with:
name: lambdas
path: |
cfn-lambda.zip
eventbridge-lambda.zip
- name: Cleanup common folders
run: |
rm -rf cfn-lambda/common
rm -rf eventbridge-lambda/common
# Upload built artifacts to S3
upload_to_buckets:
name: Upload to S3 buckets
runs-on: ubuntu-latest
needs: build_function
needs: build_functions
strategy:
matrix:
aws_region:
Expand All @@ -40,38 +79,65 @@ jobs:
- 'us-west-1'
- 'us-west-2'
- 'eu-central-1'
- 'eu-central-2'
- 'eu-north-1'
- 'eu-west-1'
- 'eu-west-2'
- 'eu-west-3'
- 'eu-south-1'
- 'eu-south-2'
- 'sa-east-1'
- 'ap-northeast-1'
- 'ap-northeast-2'
- 'ap-northeast-3'
- 'ap-south-1'
- 'ap-south-2'
- 'ap-southeast-1'
- 'ap-southeast-2'
- 'ap-southeast-3'
- 'ap-southeast-4'
- 'ap-east-1'
- 'ca-central-1'
- 'ca-west-1'
- 'af-south-1'
- 'me-south-1'
- 'me-central-1'
- 'il-central-1'
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: download zip
run: wget -c https://github.com/logzio/firehose-logs/releases/download/${{ github.event.release.tag_name }}/firehose-logs_${{ github.event.release.tag_name }}_linux_amd64.zip -O function.zip
- name: create new version

- name: Download Artifact for Lambdas
uses: actions/download-artifact@v2
with:
name: lambdas
path: .

- name: Configure AWS CLI
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ matrix.aws_region }}

- name: Upload CloudFormation Lambda ZIP to S3
run: |
aws s3 cp ./cfn-lambda.zip s3://logzio-aws-integrations-${{ matrix.aws_region }}/firehose-logs/${{ github.event.release.tag_name }}/cfn-lambda.zip --acl public-read
- name: Upload EventBridge Lambda ZIP to S3
run: |
aws s3 cp ./eventbridge-lambda.zip s3://logzio-aws-integrations-${{ matrix.aws_region }}/firehose-logs/${{ github.event.release.tag_name }}/eventbridge-lambda.zip --acl public-read
- name: Prepare SAM Template
run: |
cp ./cloudformation/sam-template.yaml ./sam-template-${{ matrix.aws_region }}.yaml
sed -i "s/<<VERSION>>/${{ github.event.release.tag_name }}/" "./sam-template-${{ matrix.aws_region }}.yaml"
sed -i "s/<<REGION>>/${{ matrix.aws_region }}/" "./sam-template-${{ matrix.aws_region }}.yaml"
- name: Upload to aws
- name: Upload SAM Template to S3
run: |
sudo apt-get update
sudo apt-get install awscli
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY }}
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_KEY }}
aws configure set region ${{ matrix.aws_region }}
aws s3 cp ./sam-template-${{ matrix.aws_region }}.yaml s3://logzio-aws-integrations-${{ matrix.aws_region }}/firehose-logs/${{ github.event.release.tag_name }}/sam-template.yaml --acl public-read
aws s3 cp ./function.zip s3://logzio-aws-integrations-${{ matrix.aws_region }}/firehose-logs/${{ github.event.release.tag_name }}/function.zip --acl public-read
- name: Clean
run: |
rm ./sam-template-${{ matrix.aws_region }}.yaml
rm ./function.zip
rm ./sam-template-${{ matrix.aws_region }}.yaml
36 changes: 32 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
before:
hooks:
- go mod tidy
builds:
- env:
- id: "cfn-lambda"
dir: "cfn-lambda/"
main: "."
binary: "bootstrap"
env:
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
goos:
- linux
goarch:
- amd64
- id: "eventbridge-lambda"
dir: "eventbridge-lambda/"
main: "."
binary: "bootstrap"
env:
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
Expand All @@ -12,10 +32,18 @@ builds:
- linux
goarch:
- amd64
binary: 'bootstrap'
archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
- id: "cfn-lambda"
builds:
- "cfn-lambda"
format: zip
name_template: 'cfn-lambda_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
- id: "eventbridge-lambda"
builds:
- "eventbridge-lambda"
format: zip
name_template: 'eventbridge-lambda_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
release:
draft: true
changelog:
skip: true
Loading

0 comments on commit c8c438d

Please sign in to comment.