-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
94 lines (77 loc) · 2.71 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
# Variables
# Info about supported regions
# https://developer.amazon.com/docs/custom-skills/host-a-custom-skill-as-an-aws-lambda-function.html
#AWS_REGION ?= "eu-west-1"
#ROLE_ARN ?= "arn:aws:iam::527878234180:role/themoviedb_alexa"
#LAMBDA_NAME ?= "TheMoviedbAlexa"
#ALEXA_SKILL_ID ?= "amzn1.ask.skill.ef144e1e-bf0e-4306-a9f6-c05a7d92d6f0"
AWS_REGION ?= "eu-west-1"
ROLE_ARN ?= ""
LAMBDA_NAME ?= "TheMoviedbAlexa"
ALEXA_SKILL_ID ?= ""
include .secret.env
.PHONY: help
.DEFAULT_GOAL := help
# Targets
release: ## Generates a lambda release
$(MAKE) deps
mix build_lambda
package: ## Generates a zip with an AWS lambda bootstrap release
$(MAKE) release
mix package
deps: ## Retrieves the project dependencies
mix deps.get
DOCKER_TAG ?= "docker_themoviebd_alexa"
DEST_FILE ?= "./output"
docker_build: ## Creates a docker build image to be used for making releases
@echo "Build docker image ${DOCKER_TAG}"
@docker build --quiet -t ${DOCKER_TAG} .
docker_run: ## Executes a container using the build image
@echo "Execute build in container"
@docker run --name ${DOCKER_TAG} ${DOCKER_TAG}
docker_copy: ## Copies the release generated by the build image into the output directory
@echo "Copy build file to ${DEST_FILE}"
@docker cp ${DOCKER_TAG}:/output/lambda.zip ${DEST_FILE}
@docker rm ${DOCKER_TAG}
docker_package: ## Creates the build image, runs the release and copies the generated bootstrap package
$(MAKE) docker_build
$(MAKE) docker_run
$(MAKE) docker_copy
LAMBDA_PATH ?= "${DEST_FILE}/lambda.zip"
create_lambda: ## Creates an AWS lambda
@echo "Creating lambda"
@aws lambda create-function \
--region ${AWS_REGION} \
--function-name ${LAMBDA_NAME} \
--handler Elixir.ThemoviedbAlexa:handle \
--role ${ROLE_ARN} \
--runtime provided \
--zip-file fileb://${LAMBDA_PATH}
@echo "done!"
update_lambda: ## Updates an AWS lambda
@echo "Update lambda"
@aws lambda update-function-code \
--region ${AWS_REGION} \
--function-name ${LAMBDA_NAME} \
--zip-file fileb://${LAMBDA_PATH} \
--publish
@echo "done!"
add_skill_permission: ## Adds lambda permissions to an Alexa skill
@echo "Add skill permission"
@aws lambda add-permission \
--region ${AWS_REGION} \
--function-name ${LAMBDA_NAME} \
--statement-id 1 \
--action lambda:InvokeFunction \
--principal alexa-appkit.amazon.com \
--event-source-token ${ALEXA_SKILL_ID}
@echo "done!"
test_lambda: ## Sends a test JSON object to the lambda
aws lambda invoke \
--function-name ${LAMBDA_NAME} \
--region ${AWS_REGION} \
--log-type Tail \
--payload '{"msg": "a fake request"}' \
outputfile.txt
help: ## Prints this help
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'