-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
114 lines (87 loc) · 3.65 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
LOCAL_URL=http://127.0.0.1:3000/
root_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
export PYENV_VERSION=3.8.11
export PYENV_ROOT=$(root_dir)/.pyenv
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
PYENV_VIRTUALENV=cdk-sam-lambda-rest
export GOSS_USE_ALPHA=1
export AWS_PROFILE ?= UNSET
help:
@echo make targets:
@awk ' \
BEGIN { FS=":.*?## " } \
$$1~/^[A-Za-z]/ && $$2~/^.+/ { \
printf " * %-18.18s %s\n",$$1":",$$2 \
}' $(MAKEFILE_LIST)
# eval "$$(pyenv init -)"; \
# eval "$$(pyenv virtualenv-init -)"; \
define venv
source $(PYENV_ROOT)/versions/$(PYENV_VIRTUALENV)/bin/activate
endef
local: ## invoke the Lambda locally
$(call venv); \
sam-beta-cdk local invoke CdkSamLambdaRestStack/MessagesHandler
echo ""
local-api: ## run the API locally
$(call venv); \
sam-beta-cdk local start-api
request req: ## submit a request to the local API service
@set -o pipefail; curl -s $(LOCAL_URL) |jq -Rr . \
|| echo "Is the service running on $(LOCAL_URL)?\nTry \`make local-api\` in another terminal"
dependencies deps: ## install dev dependencies
hash aws || brew install awscli
hash aws-vault || brew install aws-vault
hash sam-beta-cdk || { brew tap aws/tap && brew install aws/tap/aws-sam-cli-beta-cdk; }
hash cdk || npm install -g aws-cdk
hash pyenv || brew install pyenv
hash pyenv-virtualenv || brew install pyenv-virtualenv
hash goss || { echo "Please install goss -- https://goss.rocks/"; }
hash docker || { echo "Please install Docker -- https://docs.docker.com/get-docker/"; }
virtualenv: ## install python 3 and create virtualenv
pyenv install $(PYENV_VERSION)
pyenv virtualenv $(PYENV_VERSION) $(PYENV_VIRTUALENV)
requirements reqs: ## install python3 requirements
$(call venv); \
pip3 install --upgrade pip; \
pip3 install --upgrade -r requirements.txt
lint: ## check syntax of python code
@echo "Checking Python code for syntax errors (fatal)"
@$(call venv); pylint --errors-only cdklib lambda;
@echo "Checking Python code for syntax suggestions (non-fatal)"
@$(call venv); pylint --exit-zero cdklib lambda
test: unittest ## run local tests
unittest: ## run pytest
@$(call venv); \
pytest -v --maxfail=1 --log-cli-level DEBUG lambda
goss-local: local-endpoint ## run goss local checks (requires `make start-api` running elsewhere)
@printf "# Validating local deployment: $(ENDPOINT)\n\n"
@goss validate --format documentation
@printf -- "----\n\n"
goss-remote: stack-endpoint ## run goss remote checks (requires `make deploy` to complete successfully)
@printf "Validating stack deployment: $(ENDPOINT)\n\n"
@goss validate --format documentation
@printf -- "----\n\n"
bootstrap: ## initialize CDK resources in AWS
@$(call venv); \
aws-vault exec --duration 1h $(AWS_PROFILE) -- cdk bootstrap
build: ## build local SAM container
@$(call venv); \
sam-beta-cdk build
deploy: ## deploy resources to AWS with CDK
@$(call venv); \
aws-vault exec --duration 1h $(AWS_PROFILE) -- cdk deploy --app .aws-sam/build --outputs-file stack-outputs.json
destroy: ## deploy resources to AWS with CDK
@$(call venv); \
aws-vault exec --duration 1h $(AWS_PROFILE) -- cdk destroy --app .aws-sam/build
validate: check-endpoint goss-remote ## test the deployed service
local-endpoint:
$(eval export ENDPOINT="http://localhost:3000/")
stack-endpoint:
$(eval export ENDPOINT=$(shell jq -r .CdkSamLambdaRestStack.endpoint < stack-outputs.json))
check-endpoint: stack-endpoint
@printf "# HTTP response from $(ENDPOINT):\n\n"
@curl -ski -o- $(ENDPOINT) && echo ""
@printf -- "----\n\n"
endpoint: stack-endpoint ## Show the Lambda's HTTP endpoint URL
@echo "Service endpoint: $$ENDPOINT"
.PHONY: lint test unittest goss bootstrap