forked from discordianfish/blackbox-exporter-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
55 lines (41 loc) · 1.33 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
STACK_NAME ?= blackbox-exporter-lambda
ACCOUNT_ID ?= $(shell aws sts get-caller-identity --output text|cut -f1)
BUCKET ?= blackbox-exporter-$(ACCOUNT_ID)
LAMBDA_ARN = $(shell aws cloudformation describe-stacks \
--output text \
--stack-name blackbox-exporter-lambda \
--query 'Stacks[0].Outputs[?OutputKey==`LambdaArn`].OutputValue')
ENDPOINT = $(shell aws cloudformation describe-stacks \
--output text \
--stack-name blackbox-exporter-lambda \
--query 'Stacks[0].Outputs[?OutputKey==`Endpoint`].OutputValue')
BUNDLE = handler.zip
require-token:
ifndef AUTH_TOKEN
$(error AUTH_TOKEN required)
endif
all: $(BUNDLE)
handler:
go build -o handler
$(BUNDLE): handler
zip $@ $<
upload: $(BUNDLE)
aws s3 cp $< s3://$(BUCKET)/$(BUNDLE)
cfn:
aws cloudformation $(OP) \
--capabilities CAPABILITY_IAM \
--stack-name $(STACK_NAME) \
--parameters ParameterKey=FirstRun,ParameterValue=$(FIRST_RUN) ParameterKey=AuthToken,ParameterValue=$(AUTH_TOKEN) \
--template-body "$$(cat cfn/site.yml)"
new:
make cfn OP=create-stack FIRST_RUN=true
update: require-token
make cfn OP=update-stack FIRST_RUN=false
bump:
aws lambda update-function-code \
--function-name "$(LAMBDA_ARN)" \
--s3-bucket "$(BUCKET)" \
--s3-key "$(BUNDLE)"
endpoint:
@echo $(ENDPOINT)
.PHONY: handler cfn new update bump endpoint