-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
99 lines (83 loc) · 3 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
AWS_PROFILE=forwarder-profile
AWS_REGION=us-east-1
AWS_CLI_BIN="aws"
PIP3_BIN=pip3
# cfn template config
stack_name=ingestion-sandbox
sam_template=kinesis-forwarder.yaml
cfn_template=kinesis-forwarder-output.yaml
# cfn template parameters
artifacts_s3_bucket=<YOUR_BUCKET_NAME>
cross_account_role_arn=arn:aws:iam::<AWS_ACCOUNT>:role/<CROSS_ACCOUNT_ROLE_FROM_kinesis-receiver-py>
forward_to_stream_name=ReceiverStream
kinesis_stream_name=SourceStream
kinesis_stream_env_tag=Sandbox
kinesis_stream_retention_hrs=168
kinesis_stream_shard_count=1
event_source_batch_size=5
# kinesis forwarder lambda config
build_time=$(shell cat /tmp/make.build-time)
lambda_name=kinesis-forwarder-lambda
lambda_file_name=$(lambda_name)-$(build_time)
lambda_zip=dist/$(lambda_file_name).zip
lambda_export=lambda_function.lambda_handler
.PHONY: all
all: clean build-time compile package deploy
build-time:
@date +"%m-%d-%Y-%H-%M-%S" > /tmp/make.build-time
clean:
rm -rf build/* && rm -rf dist/* && rm -f /tmp/make.*
compile:
echo "starting build"
cp kinesis*py build
cp requirements.txt build
cp setup.cfg build
$(PIP3_BIN) install -r requirements.txt --target build --no-cache-dir --find-links file:///tmp/packages
package:
( cd build; zip -0r ../$(lambda_zip) . )
copy-to-s3:
$(AWS_CLI_BIN) s3 cp $(lambda_zip) s3://$(artifacts_s3_bucket)/ --profile $(AWS_PROFILE)
validate-cfn-template:
$(AWS_CLI_BIN) cloudformation validate-template \
--template-body file://$(sam_template)
package-cfn-template:
$(AWS_CLI_BIN) cloudformation package \
--template-file $(sam_template) \
--output-template-file $(cfn_template) \
--s3-bucket $(artifacts_s3_bucket) \
--region $(AWS_REGION) \
--profile $(AWS_PROFILE)
deploy-cfn-template:
$(AWS_CLI_BIN) cloudformation deploy \
--template-file $(cfn_template) \
--stack-name $(stack_name) \
--parameter-overrides \
ArtificatS3Bucket=$(artifacts_s3_bucket) \
LambdaZipFile=$(lambda_file_name).zip \
CrossAccountRoleArn=$(cross_account_role_arn) \
ForwardToStreamName=$(forward_to_stream_name) \
KinesisStreamName=$(kinesis_stream_name) \
KinesisStreamRetentionHours=$(kinesis_stream_retention_hrs) \
KinesisStreamShardCount=$(kinesis_stream_shard_count) \
KinesisStreamEnv=$(kinesis_stream_env_tag) \
EventSourceBatchSize=$(event_source_batch_size) \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM \
--no-fail-on-empty-changeset \
--region $(AWS_REGION) \
--profile $(AWS_PROFILE)
update-lambda-test:
$(AWS_CLI_BIN) lambda update-function-code \
--function-name $(lambda_name) \
--zip-file fileb://$(lambda_zip) \
--region $(AWS_REGION) \
--profile $(AWS_PROFILE)
deploy: copy-to-s3 validate-cfn-template package-cfn-template deploy-cfn-template
# some tests for build-time. We want to make sure that 'build-time' variable
# contains a constant timestamp value.
# Execute 'make build-time-test' to test
build-time-test: clean build-time build-time-1 build-time-2
build-time-1:
@echo $(build_time)
sleep 4s
build-time-2:
@echo $(build_time)