forked from apiaryio/cloudwatch-to-papertrail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
63 lines (51 loc) · 1.89 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
APP ?= app_name
PROGRAM ?= default
LOG_GROUP ?= log_group_name
HOST ?= logs.papertrailapp.com
PORT ?= 1234
DATADOG ?=
WAIT_FOR_FLUSH ?= false
ALNUM_LOG_GROUP = $(shell echo $(LOG_GROUP) | sed 's/[^[:alnum:]]/_/g')
ACCOUNT_ID = $(shell aws sts get-caller-identity --output text --query Account)
all: lambda log
deps:
rm -rf node_modules
npm install
env:
rm -f env.json
echo "{\"host\": \"$(HOST)\", \"port\": $(PORT), \"appname\": \"$(APP)\", \"program\": \"$(PROGRAM)\", \"datadog\": \"$(DATADOG)\", \"waitForFlush\": $(WAIT_FOR_FLUSH)}" > env.json
create-zip:
rm -f code.zip
zip code.zip -r index.js env.json node_modules
lambda: deps env create-zip
aws lambda create-function --publish \
--function-name $(APP)-$(PROGRAM)-to-papertrail \
--runtime nodejs16.x \
--handler index.handler \
--zip-file fileb://code.zip \
--role arn:aws:iam::$(ACCOUNT_ID):role/lambda_basic_execution
deploy: deps env create-zip
aws lambda update-function-code --publish \
--function-name $(APP)-$(PROGRAM)-to-papertrail \
--zip-file fileb://code.zip
log:
aws lambda add-permission \
--function-name $(APP)-$(PROGRAM)-to-papertrail \
--statement-id $(ALNUM_LOG_GROUP)__$(APP)-$(PROGRAM)-to-papertrail \
--principal logs.$(AWS_DEFAULT_REGION).amazonaws.com \
--action lambda:InvokeFunction \
--source-arn arn:aws:logs:$(AWS_DEFAULT_REGION):$(ACCOUNT_ID):log-group:$(LOG_GROUP):* \
--source-account $(ACCOUNT_ID)
aws logs put-subscription-filter \
--log-group-name $(LOG_GROUP) \
--destination-arn arn:aws:lambda:$(AWS_DEFAULT_REGION):$(ACCOUNT_ID):function:$(APP)-$(PROGRAM)-to-papertrail \
--filter-name LambdaStream_$(APP)-$(PROGRAM)-to-papertrail \
--filter-pattern ""
clean:
rm -f code.zip env.json
test: env
docker pull lambci/lambda
# docker run --name lambda --rm -v $(pwd):/var/task lambci/lambda index.handler '{}'
destroy:
aws lambda delete-function \
--function-name $(APP)-$(PROGRAM)-to-papertrail