Skip to content

Commit 911cf99

Browse files
authored
Merge pull request #3 from axiomhq/arne/format-files
Build CloudFormation from template and handler.py
2 parents 11eb808 + efac97f commit 911cf99

File tree

6 files changed

+173
-228
lines changed

6 files changed

+173
-228
lines changed

.github/workflows/ci.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
env:
6+
YQ_VERSION: "4.25.1"
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: psf/black@stable
14+
build:
15+
runs-on: ubuntu-latest
16+
needs:
17+
- lint
18+
steps:
19+
- uses: actions/checkout@v3
20+
- run: wget https://github.com/mikefarah/yq/releases/download/v$YQ_VERSION/yq_linux_amd64.tar.gz -O - | tar xz && mv yq_linux_amd64 /usr/local/bin/yq
21+
- run: |-
22+
mkdir build
23+
yq ".Resources.LogsLambda.Properties.Code.ZipFile = \"$(sed 's/\"/\\\"/g' handler.py)\"" axiom-cloudfront-lambda-cloudformation-stack.template.yaml > build/axiom-cloudfront-lambda-cloudformation-stack.yaml
24+
- run: cat build/axiom-cloudfront-lambda-cloudformation-stack.yaml

.github/workflows/release.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
env:
9+
YQ_VERSION: "4.25.1"
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- run: wget https://github.com/mikefarah/yq/releases/download/v$YQ_VERSION/yq_linux_amd64.tar.gz -O - | tar xz && mv yq_linux_amd64 /usr/local/bin/yq
17+
- run: |-
18+
mkdir build
19+
yq ".Resources.LogsLambda.Properties.Code.ZipFile = \"$(sed 's/\"/\\\"/g' handler.py)\"" axiom-cloudfront-lambda-cloudformation-stack.template.yaml > build/axiom-cloudfront-lambda-cloudformation-stack.yaml
20+
- uses: jakejarvis/s3-sync-action@v0.5.1
21+
env:
22+
SOURCE_DIR: build
23+
AWS_S3_BUCKET: "axiom-cloudformation-stacks"
24+
AWS_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
25+
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Parameters:
2+
BucketName:
3+
Description: The Name of the S3 Bucket.
4+
Type: String
5+
MinLength: 1
6+
AxiomToken:
7+
Description: The Token of User in Axiom. Must start with xapt- or xaat.
8+
Type: String
9+
NoEcho: true
10+
MinLength: 1
11+
AllowedPattern: "^(xaat-|xait-).*"
12+
AxiomURL:
13+
Type: String
14+
Default: "https://cloud.axiom.co"
15+
Description: The URL of Axiom endpoint. Defaults to "https://cloud.axiom.co".
16+
AxiomDataset:
17+
Type: String
18+
Description: The Name of the Dataset in Axiom.
19+
MinLength: 1
20+
Resources:
21+
LogsBucket:
22+
Type: AWS::S3::Bucket
23+
DependsOn:
24+
- LogsLambdaPermission
25+
Properties:
26+
BucketName: !Ref 'BucketName'
27+
AccessControl: Private
28+
NotificationConfiguration:
29+
LambdaConfigurations:
30+
- Event: 's3:ObjectCreated:Put'
31+
Function: !GetAtt
32+
- LogsLambda
33+
- Arn
34+
LogsRole:
35+
Type: AWS::IAM::Role
36+
Properties:
37+
AssumeRolePolicyDocument:
38+
Statement:
39+
- Action:
40+
- 'sts:AssumeRole'
41+
Effect: Allow
42+
Principal:
43+
Service:
44+
- lambda.amazonaws.com
45+
ManagedPolicyArns:
46+
- 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
47+
LogsPolicy:
48+
Type: AWS::IAM::Policy
49+
Properties:
50+
PolicyDocument:
51+
Statement:
52+
- Action:
53+
- 's3:GetObject'
54+
- 's3:ListBucket'
55+
Effect: Allow
56+
Resource:
57+
- !Join
58+
- ''
59+
- - 'arn:aws:s3:::'
60+
- !Ref 'LogsBucket'
61+
- 'arn:aws:s3:::*/*'
62+
PolicyName: axiom-cloudfront-lambda-policy
63+
Roles:
64+
- !Ref 'LogsRole'
65+
LogsLambda:
66+
Type: AWS::Lambda::Function
67+
Properties:
68+
Runtime: python3.9
69+
FunctionName: axiom-cloudfront-lambda
70+
Handler: index.lambda_handler
71+
Code:
72+
ZipFile: |
73+
# DO NOT EDIT
74+
# CI will replace these comments with the code from ./handler.py
75+
Role: !GetAtt
76+
- LogsRole
77+
- Arn
78+
Environment:
79+
Variables:
80+
AXIOM_TOKEN: !Ref 'AxiomToken'
81+
AXIOM_DATASET: !Ref 'AxiomDataset'
82+
AXIOM_URL: !Ref 'AxiomURL'
83+
LogsLambdaPermission:
84+
Type: AWS::Lambda::Permission
85+
DependsOn:
86+
- LogsLambda
87+
Properties:
88+
Action: lambda:InvokeFunction
89+
FunctionName: !Ref 'LogsLambda'
90+
Principal: s3.amazonaws.com
91+
SourceAccount: !Ref 'AWS::AccountId'
92+
SourceArn: !Sub
93+
- 'arn:aws:s3:::${BucketSub}'
94+
- BucketSub: !Ref 'BucketName'

axiom-cloudfront-lambda-cloudformation-stack.yaml

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

0 commit comments

Comments
 (0)