├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── gradle.xml
├── libraries
│ ├── Gradle__com_amazonaws_aws_lambda_java_core_1_1_0.xml
│ ├── Gradle__com_amazonaws_aws_lambda_java_events_2_0_1.xml
│ ├── Gradle__com_amazonaws_aws_lambda_java_log4j2_1_0_0.xml
│ ├── Gradle__com_fasterxml_jackson_core_jackson_annotations_2_8_5.xml
│ ├── Gradle__com_fasterxml_jackson_core_jackson_core_2_8_5.xml
│ ├── Gradle__com_fasterxml_jackson_core_jackson_databind_2_8_5.xml
│ ├── Gradle__joda_time_joda_time_2_6.xml
│ ├── Gradle__org_apache_logging_log4j_log4j_api_2_8_2.xml
│ ├── Gradle__org_apache_logging_log4j_log4j_core_2_8_2.xml
│ └── Gradle__org_jetbrains_annotations_13_0.xml
├── misc.xml
├── modules.xml
├── modules
│ ├── com.myblockbuster.iml
│ ├── com.myblockbuster_main.iml
│ └── com.myblockbuster_test.iml
├── sonarIssues.xml
├── sonarlint
│ └── issuestore
│ │ └── index.pb
├── vcs.xml
└── workspace.xml
├── LICENSE
├── README.md
├── build.gradle
├── docker-compose.yml
├── gradle
└── wrapper
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── localstack.json
├── out
├── production
│ ├── classes
│ │ └── META-INF
│ │ │ └── com.myblockbuster_main.kotlin_module
│ └── resources
│ │ ├── helloEvent.json
│ │ ├── log4j2.xml
│ │ └── routes.yml
└── test
│ ├── classes
│ └── META-INF
│ │ └── com.myblockbuster_main.kotlin_module
│ └── resources
│ └── eventMovieGET.json
├── package-lock.json
├── package.json
├── serverless.yml
├── settings.gradle
└── src
├── main
├── kotlin
│ └── com
│ │ └── myblockbuster
│ │ ├── ApiGatewayResponse.kt
│ │ ├── Handler.kt
│ │ ├── Response.kt
│ │ ├── core
│ │ ├── controllers
│ │ │ └── Controller.kt
│ │ ├── dispatchers
│ │ │ ├── Dispatcher.kt
│ │ │ └── RequestDispatcher.kt
│ │ ├── exceptions.kt
│ │ ├── factories
│ │ │ ├── Factory.kt
│ │ │ └── ServiceFactory.kt
│ │ ├── models.kt
│ │ └── services
│ │ │ └── Service.kt
│ │ └── movies
│ │ ├── controllers
│ │ └── MovieController.kt
│ │ ├── exceptions.kt
│ │ ├── models.kt
│ │ └── services
│ │ └── MovieService.kt
└── resources
│ ├── helloEvent.json
│ ├── log4j2.xml
│ └── routes.yml
└── test
├── kotlin
├── .gitkeep
└── com
│ └── myblockbuster
│ ├── TestHandler.kt
│ └── models.kt
└── resources
└── eventMovieGET.json
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | .gradle
3 | /build/
4 | /bin/
5 | /.settings/
6 | .project
7 | .classpath
8 |
9 | # Package Files
10 | *.jar
11 | *.war
12 | *.ear
13 |
14 | # Serverless directories
15 | .serverless
16 |
17 | # SAM-Local
18 | template.yml
19 |
20 | # NODE JS
21 |
22 | # Logs
23 | logs
24 | *.log
25 | npm-debug.log*
26 | yarn-debug.log*
27 | yarn-error.log*
28 |
29 | # Runtime data
30 | pids
31 | *.pid
32 | *.seed
33 | *.pid.lock
34 |
35 | # Directory for instrumented libs generated by jscoverage/JSCover
36 | lib-cov
37 |
38 | # Coverage directory used by tools like istanbul
39 | coverage
40 |
41 | # nyc test coverage
42 | .nyc_output
43 |
44 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
45 | .grunt
46 |
47 | # Bower dependency directory (https://bower.io/)
48 | bower_components
49 |
50 | # node-waf configuration
51 | .lock-wscript
52 |
53 | # Compiled binary addons (https://nodejs.org/api/addons.html)
54 | build/Release
55 |
56 | # Dependency directories
57 | node_modules/
58 | jspm_packages/
59 |
60 | # Typescript v1 declaration files
61 | typings/
62 |
63 | # Optional npm cache directory
64 | .npm
65 |
66 | # Optional eslint cache
67 | .eslintcache
68 |
69 | # Optional REPL history
70 | .node_repl_history
71 |
72 | # Output of 'npm pack'
73 | *.tgz
74 |
75 | # Yarn Integrity file
76 | .yarn-integrity
77 |
78 | # dotenv environment variables file
79 | .env
80 |
81 | # next.js build output
82 | .next
83 |
84 | # Exclude Test logs
85 | test.log
86 | apt-cyg
87 | outfile
88 |
89 | # Exclude IntelliJ files
90 | .idea
91 |
92 | # Exclude .localstack folder
93 | .localstack
94 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | com.myblockbuster
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_amazonaws_aws_lambda_java_core_1_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_amazonaws_aws_lambda_java_events_2_0_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_amazonaws_aws_lambda_java_log4j2_1_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_annotations_2_8_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_core_2_8_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_databind_2_8_5.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__joda_time_joda_time_2_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__org_apache_logging_log4j_log4j_api_2_8_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__org_apache_logging_log4j_log4j_core_2_8_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/modules/com.myblockbuster.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/modules/com.myblockbuster_main.iml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/modules/com.myblockbuster_test.iml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/sonarIssues.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
287 |
288 |
289 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/index.pb:
--------------------------------------------------------------------------------
1 |
2 | 7
3 | gradlew,5/b/5bbfa66edb4db3c7c33c5181f43510990d3307f9
4 | ;
5 | gradlew.bat,2/a/2a45a911a8f1836b0b6c5b758962572012d8f8c3
6 | <
7 | build.gradle,f/0/f07866736216be0ee2aba49e392191aeae700a35
8 | R
9 | "src/main/resources/helloEvent.json,9/5/9551bcc38cd3ea08dbd238b9b34a87908ad4b6ec
10 | \
11 | ,src/main/kotlin/com/myblockbuster/Handler.kt,7/d/7d63cd8fd8ae6f8a3dd6e3dce14ee4396745b15b
12 | 9
13 | README.md,8/e/8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d
14 | _
15 | /node_modules/serverless-sam/lib/SamGenerator.js,e/e/eedceba5a276f2b78bc0cef968ed646afbe8a823
16 | d
17 | 4node_modules/serverless-sam/lib/FunctionConverter.js,f/4/f4821f5e18cc3438e29e6dbf4d35f31367414c7f
18 | >
19 | serverless.yml,5/9/5948f757250f0c470b076eb7741987cdad7a536f
20 | ?
21 | settings.gradle,0/5/05efc8b1657769a27696d478ded1e95f38737233
22 | <
23 | template.yml,8/1/819c91fe9ef2286228daa192ef9a65ce74bf3ef0
24 | Q
25 | !.serverless/serverless-state.json,a/f/afb2f6df63255fd98fce321fd51401205576d934
26 | :
27 |
28 | .gitignore,a/5/a5cc2925ca8258af241be7e5b0381edf30266302
29 | <
30 | package.json,7/0/7030d0b2f71b999ff89a343de08c414af32fc93a
31 | A
32 | package-lock.json,f/a/fa288d1472d29beccb489a676f68739ad365fc47
33 | U
34 | %src/test/resources/eventMovieGET.json,7/c/7cffdcf34cff9646ad917c1b06ff45c49cb1577e
35 | e
36 | 5.serverless/cloudformation-template-update-stack.json,7/e/7e51251bde10cbffad666261b08344da1f050e4a
37 | B
38 | docker-compose.yml,3/5/35b8c13cf2eb2a194eada000eb310d65aed53b2a
39 | ?
40 | localstack.json,a/8/a8991ef63cc43515476e6239b143e1fc40b912a7
41 | 7
42 | apt-cyg,7/f/7f043a009e04981f721fa89d6f0b7e97dc7645d4
43 | p
44 | @src/main/kotlin/com/myblockbuster/core/dispatchers/Dispatcher.kt,7/b/7b4fc241ed64848b5e58c773e9c52c24b1904e98
45 | w
46 | Gsrc/main/kotlin/com/myblockbuster/core/dispatchers/RequestDispatcher.kt,b/a/baae4da613795bae98fb2cc5858b5d1e80197ca7
47 | ]
48 | -src/main/kotlin/com/myblockbuster/Response.kt,1/5/1587f858e40c45f40e35610ca73ca148b6fc0d4b
49 | g
50 | 7src/main/kotlin/com/myblockbuster/ApiGatewayResponse.kt,7/4/74868ba4f4229cfb0b5833a9f3361fae98badadc
51 | d
52 | 4src/main/kotlin/com/myblockbuster/core/exceptions.kt,2/b/2b15987564cd19245eb7ffa4b5d809940a009ed9
53 | p
54 | @src/main/kotlin/com/myblockbuster/core/controllers/Controller.kt,d/c/dcfd4c3b970682df894ffd319e483a28d5360051
55 | j
56 | :src/main/kotlin/com/myblockbuster/core/services/Service.kt,e/d/ed7956c19aaf428988c52a7fc964868a6a6c5d15
57 | `
58 | 0src/main/kotlin/com/myblockbuster/core/models.kt,2/5/25eeadc2174494c949f75525e935b56323c75e46
59 | q
60 | Asrc/main/kotlin/com/myblockbuster/movies/services/MovieService.kt,1/a/1aa0fb19e1a51ced7a1f63bfec1b423fa53ab6ef
61 | f
62 | 6src/main/kotlin/com/myblockbuster/movies/exceptions.kt,a/9/a98bb1a3253f2361966f54701853546fb0a84bb6
63 | b
64 | 2src/main/kotlin/com/myblockbuster/movies/models.kt,4/7/4762c245f394ad30d3c52c2cebca29efc514ab5d
65 | k
66 | ;src/main/kotlin/com/myblockbuster/core/factories/Factory.kt,5/e/5e89280a1fa28daf0e34b1e4b39003a94fa6ecf1
67 | r
68 | Bsrc/main/kotlin/com/myblockbuster/core/factories/ServiceFactory.kt,6/a/6a51d6e416c0924386bb16497747cb3db14b909d
69 | w
70 | Gsrc/main/kotlin/com/myblockbuster/movies/controllers/MovieController.kt,7/0/7013e38aa8e719236ddb35fa205f9dab1a9522a3
71 | 7
72 | LICENSE,0/3/0398ccd0f49298b10a3d76a47800d2ebecd49859
73 | M
74 | src/main/resources/routes.yml,9/a/9ad275fc10498d8fc3acefbe80720c889d1ad370
75 | [
76 | +src/test/kotlin/com/myblockbuster/models.kt,4/5/45153ea1dc137b9f84ff067bb68ccfa1f4c89fa8
77 | `
78 | 0src/test/kotlin/com/myblockbuster/TestHandler.kt,a/f/af77dfaef409d7c18e6342822d08731e93a2ac1d
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
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 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | this.serverless.service
137 | memo
138 | plugins
139 | sh
140 | api
141 | zip
142 | dev
143 | BaseM
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
154 |
155 |
156 |
159 |
160 |
161 |
179 |
180 |
181 |
367 |
368 |
369 |
377 |
378 |
379 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 | true
654 | DEFINITION_ORDER
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 |
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
729 |
730 |
731 |
732 |
733 |
734 |
735 |
736 |
737 |
738 |
739 |
740 |
741 |
742 |
743 |
744 |
745 |
746 |
747 |
748 |
749 |
750 |
751 |
752 |
753 |
754 |
755 |
756 |
757 |
758 |
759 |
760 |
761 |
762 |
763 |
764 |
765 |
766 |
767 |
768 |
769 |
770 |
771 |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 |
780 |
781 |
782 |
783 |
784 |
785 |
786 |
787 |
788 |
789 |
790 |
791 |
792 |
793 |
794 |
795 |
796 |
797 |
798 |
799 |
800 |
801 |
802 |
803 |
804 |
805 |
806 |
807 |
808 |
809 |
810 |
811 |
812 |
813 |
814 |
815 |
816 |
817 |
818 |
819 |
820 |
821 |
822 |
823 |
824 |
825 |
826 |
827 |
828 |
829 |
830 |
831 |
832 |
833 |
834 |
835 |
836 |
837 |
838 |
839 |
840 |
841 |
842 |
843 |
844 |
845 |
846 |
847 |
848 |
849 |
850 |
851 |
852 |
853 |
854 |
855 |
856 |
857 |
858 |
859 |
860 |
861 |
862 |
863 |
864 |
865 |
866 |
867 |
868 |
869 |
870 |
871 |
872 |
873 |
874 | 1520282989550
875 |
876 |
877 | 1520282989550
878 |
879 |
880 |
881 |
882 |
883 |
884 |
885 |
886 |
887 |
888 |
889 |
890 |
891 |
892 |
893 |
894 |
895 |
896 |
897 |
898 |
899 |
900 |
901 |
902 |
903 |
904 |
905 |
906 |
907 |
908 |
909 |
910 |
911 |
912 |
913 |
914 |
915 |
916 |
917 |
918 |
919 |
920 |
921 |
922 |
923 |
924 |
925 |
926 |
927 |
928 |
929 |
930 |
931 |
932 |
933 |
934 |
935 |
936 |
937 |
938 |
939 |
940 |
941 |
942 |
943 |
944 |
945 |
946 |
947 |
948 |
949 |
950 |
951 |
952 |
953 |
954 |
955 |
956 |
957 |
958 |
959 |
960 |
961 |
962 |
963 |
964 |
965 |
966 |
967 |
968 |
969 |
970 |
971 | file://$PROJECT_DIR$/src/test/kotlin/com/myblockbuster/TestHandler.kt
972 | 2
973 |
974 |
975 |
976 |
977 |
978 |
979 |
980 |
981 |
982 |
983 |
984 |
985 |
986 |
987 |
988 |
989 |
990 |
991 |
992 |
993 |
994 |
995 |
996 |
997 |
998 |
999 |
1000 |
1001 |
1002 |
1003 |
1004 |
1005 |
1006 |
1007 |
1008 |
1009 |
1010 |
1011 |
1012 |
1013 |
1014 |
1015 |
1016 |
1017 |
1018 |
1019 |
1020 |
1021 |
1022 |
1023 |
1024 |
1025 |
1026 |
1027 |
1028 |
1029 |
1030 |
1031 |
1032 |
1033 |
1034 |
1035 |
1036 |
1037 |
1038 |
1039 |
1040 |
1041 |
1042 |
1043 |
1044 |
1045 |
1046 |
1047 |
1048 |
1049 |
1050 |
1051 |
1052 |
1053 |
1054 |
1055 |
1056 |
1057 |
1058 |
1059 |
1060 |
1061 |
1062 |
1063 |
1064 |
1065 |
1066 |
1067 |
1068 |
1069 |
1070 |
1071 |
1072 |
1073 |
1074 |
1075 |
1076 |
1077 |
1078 |
1079 |
1080 |
1081 |
1082 |
1083 |
1084 |
1085 |
1086 |
1087 |
1088 |
1089 |
1090 |
1091 |
1092 |
1093 |
1094 |
1095 |
1096 |
1097 |
1098 |
1099 |
1100 |
1101 |
1102 |
1103 |
1104 |
1105 |
1106 |
1107 |
1108 |
1109 |
1110 |
1111 |
1112 |
1113 |
1114 |
1115 |
1116 |
1117 |
1118 |
1119 |
1120 |
1121 |
1122 |
1123 |
1124 |
1125 |
1126 |
1127 |
1128 |
1129 |
1130 |
1131 |
1132 |
1133 |
1134 |
1135 |
1136 |
1137 |
1138 |
1139 |
1140 |
1141 |
1142 |
1143 |
1144 |
1145 |
1146 |
1147 |
1148 |
1149 |
1150 |
1151 |
1152 |
1153 |
1154 |
1155 |
1156 |
1157 |
1158 |
1159 |
1160 |
1161 |
1162 |
1163 |
1164 |
1165 |
1166 |
1167 |
1168 |
1169 |
1170 |
1171 |
1172 |
1173 |
1174 |
1175 |
1176 |
1177 |
1178 |
1179 |
1180 |
1181 |
1182 |
1183 |
1184 |
1185 |
1186 |
1187 |
1188 |
1189 |
1190 |
1191 |
1192 |
1193 |
1194 |
1195 |
1196 |
1197 |
1198 |
1199 |
1200 |
1201 |
1202 |
1203 |
1204 |
1205 |
1206 |
1207 |
1208 |
1209 |
1210 |
1211 |
1212 |
1213 |
1214 |
1215 |
1216 |
1217 |
1218 |
1219 |
1220 |
1221 |
1222 |
1223 |
1224 |
1225 |
1226 |
1227 |
1228 |
1229 |
1230 |
1231 |
1232 |
1233 |
1234 |
1235 |
1236 |
1237 |
1238 |
1239 |
1240 |
1241 |
1242 |
1243 |
1244 |
1245 |
1246 |
1247 |
1248 |
1249 |
1250 |
1251 |
1252 |
1253 |
1254 |
1255 |
1256 |
1257 |
1258 |
1259 |
1260 |
1261 |
1262 |
1263 |
1264 |
1265 |
1266 |
1267 |
1268 |
1269 |
1270 |
1271 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Using Kotlin in a Serverless Architecture with AWS Lambda
2 | Complete code per article for the complete series in medium https://medium.com/@juancho088/using-kotlin-in-a-serverless-architecture-with-aws-lambda-part-1-setting-up-the-project-87033790e2f4
3 |
4 | # First Steps
5 |
6 | 1. Install nodeJS (download [link](https://nodejs.org/en/download/))
7 | 2. Run the command `npm install -g serverless`
8 | 3. Create your project running the command `serverless create —-template aws-kotlin-jvm-gradle --path your_service`
9 | 4. To configure your AWS credentials execute `serverless config credentials --provider aws --key EXAMPLE --secret EXAMPLEKEY`
10 |
11 | # Package JSON
12 |
13 | 1. Create a package.json file with the minimum information so you can install serverless libraries.
14 | ```
15 | {
16 | "name": "my-blockbuster",
17 | "version": "1.0.0"
18 | }
19 | ```
20 |
21 | # Plugins
22 |
23 | ## Serverless to SAM Local
24 |
25 | You must have a functional Docker client on the system you plan to use SAM, so install that first if you don’t yet have it!
26 |
27 | ```
28 | npm install --save-dev serverless-sam
29 | ```
30 |
31 | Add the plugin in the serverless.yml file:
32 |
33 | ```
34 | plugins:
35 | - serverless-sam
36 | ```
37 |
38 | Compile your function using Shadow, that will generate a set of files in *build/libs/*:
39 |
40 | ````
41 | gradle build shadowJar
42 | ````
43 |
44 | Export and invoke your functions
45 |
46 | ```
47 | sls sam export -o template.yml
48 | sam local invoke hello <<< "{}"
49 | ```
50 |
51 | *Note:* You will always need to run this command every single time you want to test your lambda function.
52 | Also, by default the function names will start with capital letter.
53 |
54 | To invoke custom event.json files you can execute the next command:
55 |
56 | ```
57 | $ sam local invoke Hello -e src/main/resources/event.json
58 | ```
59 |
60 | *Note:* Serverless to SAM-local plugin has an error with the memory and timeout values (in general with most
61 | od the provider properties). To solve it, change the autogenerated template.yml to include the values
62 | that you defined in your serverless.yml file.
63 |
64 | ````
65 | MemorySize: 1024
66 | Timeout: 10
67 | ````
68 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'maven'
3 |
4 | group = 'com.myblockbuster'
5 | version = 'dev'
6 |
7 | description = """My Blockbuster"""
8 |
9 |
10 | sourceCompatibility = 1.5
11 | targetCompatibility = 1.5
12 | tasks.withType(JavaCompile) {
13 | options.encoding = 'UTF-8'
14 | }
15 |
16 | buildscript {
17 | repositories {
18 | mavenCentral()
19 | maven { url "https://plugins.gradle.org/m2/" }
20 | }
21 | dependencies {
22 | classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.21'
23 | classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
24 | classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
25 | classpath "com.github.jengelman.gradle.plugins:shadow:2.0.1"
26 | classpath "de.sebastianboegl.gradle.plugins:shadow-log4j-transformer:2.1.1"
27 | }
28 | }
29 |
30 | apply plugin: 'kotlin'
31 | apply plugin: 'org.junit.platform.gradle.plugin'
32 | apply plugin: "io.spring.dependency-management"
33 | apply plugin: 'com.github.johnrengelman.shadow'
34 | apply plugin: "de.sebastianboegl.shadow.transformer.log4j"
35 |
36 | junitPlatform {
37 | filters {
38 | engines {
39 | include 'spek'
40 | }
41 | }
42 | }
43 |
44 | repositories {
45 | maven { url "http://repo.maven.apache.org/maven2" }
46 | maven { url "http://dl.bintray.com/jetbrains/spek" }
47 | }
48 |
49 | // If requiring AWS JDK, uncomment the dependencyManagement to use the bill of materials
50 | // https://aws.amazon.com/blogs/developer/managing-dependencies-with-aws-sdk-for-java-bill-of-materials-module-bom/
51 | //dependencyManagement {
52 | // imports {
53 | // mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.206'
54 | // }
55 | //}
56 |
57 | dependencies {
58 | compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.2.21'
59 | compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.1.1'
60 |
61 | compile group: 'com.amazonaws', name: 'aws-lambda-java-core', version:'1.1.0'
62 | compile group: 'com.amazonaws', name: 'aws-lambda-java-log4j2', version:'1.0.0'
63 | compile group: 'com.amazonaws', name: 'aws-lambda-java-events', version:'2.0.1'
64 |
65 | compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version:'2.8.5'
66 | compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.8.5'
67 | compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version:'2.8.5'
68 | compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.1.2'
69 |
70 | testCompile 'org.mockito:mockito-core:2.+'
71 | testCompile 'com.nhaarman:mockito-kotlin:1.5+'
72 | testCompile 'org.jetbrains.spek:spek-api:1.1.5'
73 | testCompile 'org.junit.platform:junit-platform-runner:1.0.0'
74 |
75 | testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.5'
76 | }
77 |
78 | shadowJar {
79 | zip64 true
80 | }
81 |
82 | /*
83 | task myZip(type: Zip) {
84 | archiveName "com.myblockbuster-${version}-all.zip"
85 | destinationDir(file('build/libs/'))
86 | }
87 | */
88 |
89 | task buildZip(type: Zip, dependsOn: shadowJar) {
90 | from 'build/libs/'
91 | include '*-all.jar'
92 | archiveName "com.myblockbuster-${version}-all.zip"
93 | destinationDir(file('build/libs/'))
94 |
95 | }
96 |
97 | task deploy(type: Exec, dependsOn: 'buildZip') {
98 | commandLine 'serverless', 'deploy'
99 | }
100 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '2.1'
2 |
3 | services:
4 | localstack:
5 | image: localstack/localstack
6 | privileged: true
7 | ports:
8 | - "4567-4583:4567-4583"
9 | - "8080:8080"
10 | environment:
11 | - SERVICES=${SERVICES- }
12 | - DEBUG=${DEBUG- }
13 | - DATA_DIR=${DATA_DIR- }
14 | - PORT_WEB_UI=${PORT_WEB_UI- }
15 | - LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
16 | - KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
17 | - DOCKER_HOST=unix:///var/run/docker.sock
18 | volumes:
19 | - "./.localstack:/tmp/localstack"
20 | - "/var/run/docker.sock:/var/run/docker.sock"
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Aug 05 21:19:15 SAST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/localstack.json:
--------------------------------------------------------------------------------
1 | {
2 | "APIGateway": "http://localhost:4567",
3 | "CloudFormation": "http://localhost:4581",
4 | "CloudWatch":"http://localhost:4582",
5 | "DynamoDB": "http://localhost:4569",
6 | "DynamoDBStreams": "http://localhost:4570",
7 | "ES": "http://localhost:4571",
8 | "Firehose": "http://localhost:4573",
9 | "Kinesis": "http://localhost:4568",
10 | "Lambda": "http://localhost:4574",
11 | "Redshift": "http://localhost:4577",
12 | "Route53": "http://localhost:4580",
13 | "S3": "http://localhost:4572",
14 | "SES": "http://localhost:4579",
15 | "SNS": "http://localhost:4575",
16 | "SQS": "http://localhost:4576"
17 | }
--------------------------------------------------------------------------------
/out/production/classes/META-INF/com.myblockbuster_main.kotlin_module:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/out/production/resources/helloEvent.json:
--------------------------------------------------------------------------------
1 | {
2 | "event": "hello"
3 | }
--------------------------------------------------------------------------------
/out/production/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/out/production/resources/routes.yml:
--------------------------------------------------------------------------------
1 | routes:
2 | # =========================
3 | # Movies Microservice
4 | # =========================
5 |
6 | - regex: '^/movie(/*+)?$'
7 | cls: com.myblockbuster.movies.controllers.MovieController
8 | func: movie
9 |
10 | # =========================
11 | # User Microservice
12 | # =========================
13 |
14 | - regex: '^/login(/)?$'
15 | cls: com.myblockbuster.users.controllers.UserController
16 | func: login
17 | - regex: '^/logout(/)?$'
18 | cls: com.myblockbuster.users.controllers.UserController
19 | func: logout
20 | - regex: '^/signup(/)?$'
21 | cls: com.myblockbuster.users.controllers.UserController
22 | func: signup
23 |
24 | # =========================
25 | # Geolocation Microservice
26 | # =========================
27 |
28 | - regex: '^/location/country(/*+)?$'
29 | cls: com.myblockbuster.geolocation.controllers.LocationController
30 | func: country
31 | - regex: '^/location/region(/*+)?$'
32 | cls: com.myblockbuster.geolocation.controllers.LocationController
33 | func: region
34 | - regex: '^/location/city(/*+)?$'
35 | cls: com.myblockbuster.geolocation.controllers.LocationController
36 | func: region
--------------------------------------------------------------------------------
/out/test/classes/META-INF/com.myblockbuster_main.kotlin_module:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/out/test/resources/eventMovieGET.json:
--------------------------------------------------------------------------------
1 | {
2 | "resource": "/movies/{id}",
3 | "path": "/movies",
4 | "httpMethod": "GET",
5 | "headers": {
6 | "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
7 | "Accept-Encoding": "gzip, deflate, br",
8 | "Accept-Language": "en-GB,en-US;q=0.8,en;q=0.6,zh-CN;q=0.4",
9 | "cache-control": "max-age=0",
10 | "CloudFront-Forwarded-Proto": "https",
11 | "CloudFront-Is-Desktop-Viewer": "true",
12 | "CloudFront-Is-Mobile-Viewer": "false",
13 | "CloudFront-Is-SmartTV-Viewer": "false",
14 | "CloudFront-Is-Tablet-Viewer": "false",
15 | "CloudFront-Viewer-Country": "GB",
16 | "content-type": "application/x-www-form-urlencoded",
17 | "Host": "j3ap25j034.execute-api.eu-west-2.amazonaws.com",
18 | "origin": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com",
19 | "Referer": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com/dev/",
20 | "upgrade-insecure-requests": "1",
21 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
22 | "Via": "2.0 a3650115c5e21e2b5d133ce84464bea3.cloudfront.net (CloudFront)",
23 | "X-Amz-Cf-Id": "0nDeiXnReyHYCkv8cc150MWCFCLFPbJoTs1mexDuKe2WJwK5ANgv2A==",
24 | "X-Amzn-Trace-Id": "Root=1-597079de-75fec8453f6fd4812414a4cd",
25 | "X-Forwarded-For": "50.129.117.14, 50.112.234.94",
26 | "X-Forwarded-Port": "443",
27 | "X-Forwarded-Proto": "https"
28 | },
29 | "queryStringParameters": null,
30 | "pathParameters": null,
31 | "stageVariables": null,
32 | "requestContext": {
33 | "path": "/dev/",
34 | "accountId": "125002137610",
35 | "resourceId": "qdolsr1yhk",
36 | "stage": "dev",
37 | "requestId": "0f2431a2-6d2f-11e7-b75152aa497861",
38 | "identity": {
39 | "cognitoIdentityPoolId": null,
40 | "accountId": null,
41 | "cognitoIdentityId": null,
42 | "caller": null,
43 | "apiKey": "",
44 | "sourceIp": "50.129.117.14",
45 | "accessKey": null,
46 | "cognitoAuthenticationType": null,
47 | "cognitoAuthenticationProvider": null,
48 | "userArn": null,
49 | "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
50 | "user": null
51 | },
52 | "resourcePath": "/movies/{id}",
53 | "httpMethod": "GET",
54 | "apiId": "j3azlsj0c4"
55 | },
56 | "body": null,
57 | "isBase64Encoded": false
58 | }
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-blockbuster",
3 | "version": "1.0.0",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "argparse": {
8 | "version": "1.0.10",
9 | "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
10 | "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
11 | "dev": true,
12 | "requires": {
13 | "sprintf-js": "1.0.3"
14 | }
15 | },
16 | "array-uniq": {
17 | "version": "1.0.2",
18 | "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.2.tgz",
19 | "integrity": "sha1-X8w3OSB3VyPP1k1lxkvvU7+eum0=",
20 | "dev": true
21 | },
22 | "aws-sdk": {
23 | "version": "2.209.0",
24 | "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.209.0.tgz",
25 | "integrity": "sha1-z+bKI3NvZlkystFMyOTknX6dIMw=",
26 | "dev": true,
27 | "requires": {
28 | "buffer": "4.9.1",
29 | "events": "1.1.1",
30 | "jmespath": "0.15.0",
31 | "querystring": "0.2.0",
32 | "sax": "1.2.1",
33 | "url": "0.10.3",
34 | "uuid": "3.1.0",
35 | "xml2js": "0.4.17",
36 | "xmlbuilder": "4.2.1"
37 | }
38 | },
39 | "base64-js": {
40 | "version": "1.2.3",
41 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.2.3.tgz",
42 | "integrity": "sha512-MsAhsUW1GxCdgYSO6tAfZrNapmUKk7mWx/k5mFY/A1gBtkaCaNapTg+FExCw1r9yeaZhqx/xPg43xgTFH6KL5w==",
43 | "dev": true
44 | },
45 | "bluebird": {
46 | "version": "3.5.1",
47 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
48 | "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==",
49 | "dev": true
50 | },
51 | "buffer": {
52 | "version": "4.9.1",
53 | "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz",
54 | "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=",
55 | "dev": true,
56 | "requires": {
57 | "base64-js": "1.2.3",
58 | "ieee754": "1.1.8",
59 | "isarray": "1.0.0"
60 | }
61 | },
62 | "esprima": {
63 | "version": "4.0.0",
64 | "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz",
65 | "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==",
66 | "dev": true
67 | },
68 | "events": {
69 | "version": "1.1.1",
70 | "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz",
71 | "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=",
72 | "dev": true
73 | },
74 | "ieee754": {
75 | "version": "1.1.8",
76 | "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz",
77 | "integrity": "sha1-vjPUCsEO8ZJnAfbwii2G+/0a0+Q=",
78 | "dev": true
79 | },
80 | "isarray": {
81 | "version": "1.0.0",
82 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
83 | "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
84 | "dev": true
85 | },
86 | "jmespath": {
87 | "version": "0.15.0",
88 | "resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.15.0.tgz",
89 | "integrity": "sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc=",
90 | "dev": true
91 | },
92 | "js-yaml": {
93 | "version": "3.11.0",
94 | "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.11.0.tgz",
95 | "integrity": "sha512-saJstZWv7oNeOyBh3+Dx1qWzhW0+e6/8eDzo7p5rDFqxntSztloLtuKu+Ejhtq82jsilwOIZYsCz+lIjthg1Hw==",
96 | "dev": true,
97 | "requires": {
98 | "argparse": "1.0.10",
99 | "esprima": "4.0.0"
100 | }
101 | },
102 | "lodash": {
103 | "version": "4.17.5",
104 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz",
105 | "integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==",
106 | "dev": true
107 | },
108 | "punycode": {
109 | "version": "1.3.2",
110 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz",
111 | "integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0=",
112 | "dev": true
113 | },
114 | "querystring": {
115 | "version": "0.2.0",
116 | "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
117 | "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=",
118 | "dev": true
119 | },
120 | "randomstring": {
121 | "version": "1.1.5",
122 | "resolved": "https://registry.npmjs.org/randomstring/-/randomstring-1.1.5.tgz",
123 | "integrity": "sha1-bfBij3XL1ZMpMNn+OrTpVqGFGMM=",
124 | "dev": true,
125 | "requires": {
126 | "array-uniq": "1.0.2"
127 | }
128 | },
129 | "sax": {
130 | "version": "1.2.1",
131 | "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz",
132 | "integrity": "sha1-e45lYZCyKOgaZq6nSEgNgozS03o=",
133 | "dev": true
134 | },
135 | "serverless-localstack": {
136 | "version": "0.2.3",
137 | "resolved": "https://registry.npmjs.org/serverless-localstack/-/serverless-localstack-0.2.3.tgz",
138 | "integrity": "sha1-KnxVQ0w2Dzx7o8LRS8l53EHYq9Q=",
139 | "dev": true,
140 | "requires": {
141 | "aws-sdk": "2.209.0",
142 | "bluebird": "3.5.1"
143 | }
144 | },
145 | "serverless-sam": {
146 | "version": "0.0.4",
147 | "resolved": "https://registry.npmjs.org/serverless-sam/-/serverless-sam-0.0.4.tgz",
148 | "integrity": "sha1-JnVIkKGWWebgJ/tTA7Lstpi8GSM=",
149 | "dev": true,
150 | "requires": {
151 | "bluebird": "3.5.1",
152 | "js-yaml": "3.11.0",
153 | "randomstring": "1.1.5"
154 | }
155 | },
156 | "sprintf-js": {
157 | "version": "1.0.3",
158 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
159 | "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
160 | "dev": true
161 | },
162 | "url": {
163 | "version": "0.10.3",
164 | "resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz",
165 | "integrity": "sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ=",
166 | "dev": true,
167 | "requires": {
168 | "punycode": "1.3.2",
169 | "querystring": "0.2.0"
170 | }
171 | },
172 | "uuid": {
173 | "version": "3.1.0",
174 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz",
175 | "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==",
176 | "dev": true
177 | },
178 | "xml2js": {
179 | "version": "0.4.17",
180 | "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.17.tgz",
181 | "integrity": "sha1-F76T6q4/O3eTWceVtBlwWogX6Gg=",
182 | "dev": true,
183 | "requires": {
184 | "sax": "1.2.1",
185 | "xmlbuilder": "4.2.1"
186 | }
187 | },
188 | "xmlbuilder": {
189 | "version": "4.2.1",
190 | "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-4.2.1.tgz",
191 | "integrity": "sha1-qlijBBoGb5DqoWwvU4n/GfP0YaU=",
192 | "dev": true,
193 | "requires": {
194 | "lodash": "4.17.5"
195 | }
196 | }
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-blockbuster",
3 | "version": "1.0.0",
4 | "devDependencies": {
5 | "serverless-localstack": "^0.2.3",
6 | "serverless-sam": "0.0.4"
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/serverless.yml:
--------------------------------------------------------------------------------
1 | # Welcome to Serverless!
2 | #
3 | # This file is the main config file for your service.
4 | # It's very minimal at this point and uses default values.
5 | # You can always add more config options for more control.
6 | # We've included some commented out config examples here.
7 | # Just uncomment any of them to get that config option.
8 | #
9 | # For full config options, check the docs:
10 | # docs.serverless.com
11 | #
12 | # Happy Coding!
13 |
14 | service: myblockbuster
15 |
16 | # You can pin your service to only deploy with a specific Serverless version
17 | # Check out our docs for more details
18 | # frameworkVersion: "=X.X.X"
19 |
20 | provider:
21 | name: aws
22 | runtime: java8
23 | stage: dev
24 | region: us-east-1
25 | #region: eu-west-1
26 | memorySize: 1024
27 | timeout: 10
28 |
29 | # you can add statements to the Lambda function's IAM Role here
30 | # iamRoleStatements:
31 | # - Effect: "Allow"
32 | # Action:
33 | # - "s3:ListBucket"
34 | # Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
35 | # - Effect: "Allow"
36 | # Action:
37 | # - "s3:PutObject"
38 | # Resource:
39 | # Fn::Join:
40 | # - ""
41 | # - - "arn:aws:s3:::"
42 | # - "Ref" : "ServerlessDeploymentBucket"
43 | # - "/*"
44 |
45 | # you can define service wide environment variables here
46 | # environment:
47 | # variable1: value1
48 |
49 | # you can add packaging information here
50 | package:
51 | artifact: build/libs/com.myblockbuster-dev-all.zip
52 | plugins:
53 | - serverless-sam
54 | - serverless-localstack
55 |
56 | custom:
57 | localstack:
58 | stages:
59 | - local
60 | - dev
61 | endpointFile: localstack.json
62 | functions:
63 | hello:
64 | handler: com.myblockbuster.Handler
65 | events:
66 | - http:
67 | path: hello
68 | method: get
69 |
70 | # The following are a few example events you can configure
71 | # NOTE: Please make sure to change your handler code to work with those events
72 | # Check the event documentation for details
73 | # - s3: ${env:BUCKET}
74 | # - schedule: rate(10 minutes)
75 | # - sns: greeter-topic
76 | # - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
77 | # - alexaSkill
78 | # - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
79 | # - iot:
80 | # sql: "SELECT * FROM 'some_topic'"
81 | # - cloudwatchEvent:
82 | # event:
83 | # source:
84 | # - "aws.ec2"
85 | # detail-type:
86 | # - "EC2 Instance State-change Notification"
87 | # detail:
88 | # state:
89 | # - pending
90 | # - cloudwatchLog: '/aws/lambda/hello'
91 | # - cognitoUserPool:
92 | # pool: MyUserPool
93 | # trigger: PreSignUp
94 |
95 | # Define function environment variables here
96 | # environment:
97 | # variable2: value2
98 |
99 | # you can add CloudFormation resource templates here
100 | resources:
101 | Resources:
102 | NewResource:
103 | Type: AWS::S3::Bucket
104 | Properties:
105 | BucketName: my-new-bucket
106 | # Outputs:
107 | # NewOutput:
108 | # Description: "Description for the output"
109 | # Value: "Some output value"
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'com.myblockbuster'
2 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/ApiGatewayResponse.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster
2 |
3 | import com.fasterxml.jackson.core.JsonProcessingException
4 | import com.fasterxml.jackson.databind.ObjectMapper
5 | import com.myblockbuster.core.Model
6 | import org.apache.logging.log4j.LogManager
7 | import java.nio.charset.StandardCharsets
8 | import java.util.*
9 |
10 |
11 | /**
12 | * Instead of having a generic response for everything now the Response class is an interface
13 | * and we create an specific implementation of it
14 | */
15 | class ApiGatewayResponse(
16 | val statusCode: Int = 200,
17 | var body: String? = null,
18 | val headers: Map? = Collections.emptyMap(),
19 | val isBase64Encoded: Boolean = false
20 | ): Response {
21 |
22 | companion object {
23 | inline fun build(block: Builder.() -> Unit) = Builder().apply(block).build()
24 | val LOG = LogManager.getLogger()
25 | }
26 |
27 | /**
28 | * Uses the Builder pattern to create the response
29 | */
30 | class Builder {
31 | var objectMapper: ObjectMapper = ObjectMapper()
32 |
33 | var statusCode: Int = 200
34 | var rawBody: String? = null
35 | var headers: Map? = Collections.emptyMap()
36 | var objectBody: Model? = null
37 | var listBody: List? = null
38 | var binaryBody: ByteArray? = null
39 | var base64Encoded: Boolean = false
40 |
41 | fun build(): ApiGatewayResponse {
42 | var body: String? = null
43 |
44 | when {
45 | rawBody != null -> body = rawBody as String
46 | objectBody != null || (listBody != null && listBody!!.isNotEmpty()) -> try {
47 | body = when {
48 | objectBody != null -> objectMapper.writeValueAsString(objectBody)
49 | else -> objectMapper.writeValueAsString(listBody)
50 | }
51 | } catch (e: JsonProcessingException) {
52 | LOG.error("Failed to serialize object", e)
53 | throw RuntimeException(e)
54 | }
55 | binaryBody != null -> body = String(Base64.getEncoder().encode(binaryBody), StandardCharsets.UTF_8)
56 | }
57 | return ApiGatewayResponse(statusCode, body, headers, base64Encoded)
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/Handler.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster
2 |
3 | import com.amazonaws.services.lambda.runtime.Context
4 | import com.amazonaws.services.lambda.runtime.RequestHandler
5 | import com.myblockbuster.ApiGatewayResponse.Companion.LOG
6 | import com.myblockbuster.core.*
7 | import com.myblockbuster.core.dispatchers.RequestDispatcher
8 |
9 | open class Handler: RequestHandler, ApiGatewayResponse> {
10 |
11 | var requestDispatcher: RequestDispatcher = RequestDispatcher()
12 |
13 | override fun handleRequest(input:Map, context: Context): ApiGatewayResponse {
14 |
15 | var status = 500
16 | var body: Any? = EmptyModel()
17 |
18 | try {
19 | body = requestDispatcher.locate(ApiGatewayRequest(input, context)) ?: EmptyModel()
20 |
21 | status = when (body is EmptyModel) {
22 | true -> 204
23 | false -> 200
24 | }
25 | }
26 | catch (e: MyException) {
27 | LOG.error(e.message, e)
28 | status = e.code
29 | body = ErrorModel(e.message)
30 | }
31 | catch (e: Throwable) {
32 | LOG.error(e.message, e)
33 | status = 500
34 | body = ErrorModel("Internal server error")
35 | }
36 | finally {
37 | return ApiGatewayResponse.build {
38 | statusCode = status
39 | if (body is Model)
40 | objectBody = body as Model?
41 | else
42 | listBody = body as List
43 | headers = mapOf("X-Powered-By" to "AWS Lambda & Serverless")
44 | }
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/Response.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster
2 |
3 | interface Response
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/core/controllers/Controller.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.core.controllers
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper
4 | import com.myblockbuster.core.*
5 | import com.myblockbuster.core.services.Service
6 | import kotlin.math.ceil
7 |
8 | /**
9 | * Controller that receives a request and reply with a message of type {@link M}
10 | * @param M Model type
11 | */
12 | interface Controller {
13 |
14 | companion object {
15 | // HTTP constants
16 | const val HTTP_METHOD: String = "httpMethod"
17 | const val HTTP_GET: String = "get"
18 | const val HTTP_POST: String = "post"
19 | const val HTTP_PUT: String = "put"
20 | const val HTTP_DELETE: String = "delete"
21 | const val HTTP_PATCH: String = "patch"
22 |
23 | // Pagination constants
24 | const val LIMIT: Int = 50
25 | const val MAX_LIMIT: Int = 100
26 | const val OFFSET: Int = 0
27 | const val MIN_LIMIT: Int = 0
28 | }
29 |
30 | fun anyToInt(value: Any, valueType: String = "page"): Int {
31 | return when (value) {
32 | is String -> value.toIntOrNull() ?: throw Exception("$valueType must be a number")
33 | is Int -> value
34 | else -> throw Exception("$valueType must be a number")
35 | }
36 | }
37 |
38 | fun getStringAnyMap(request: Request, key: String): Map {
39 | return if (request.input.containsKey(key) && request.input[key] != null)
40 | request.input[key] as Map
41 | else
42 | emptyMap()
43 | }
44 |
45 | fun getResource(request: Request): String {
46 | return request.input["resource"] as String
47 | }
48 |
49 | fun getHeaders(request: Request) : Map {
50 | return getStringAnyMap(request, "headers")
51 | }
52 |
53 | fun getPathParameters(request: Request) : Map {
54 | return getStringAnyMap(request, "pathParameters")
55 | }
56 |
57 | fun getQueryStringParameters(request: Request) : Map {
58 | return getStringAnyMap(request, "queryStringParameters")
59 | }
60 |
61 | fun getRawBody(request: Request) : Any {
62 | if (request.input["body"] != null)
63 | return if (request.input["body"] is String) request.input["body"] as String else request.input["body"] as Map
64 | else
65 | throw InvalidArguments("body")
66 | }
67 |
68 | fun getEntity(rawBody: Any, cls: Class): T {
69 | val objectMapper = ObjectMapper()
70 |
71 | return if (rawBody is String) objectMapper.readValue(rawBody, cls) else objectMapper.convertValue(rawBody, cls)
72 | }
73 |
74 | fun getPagination(queryParameters: Map): Pagination {
75 | var page: Int = ceil(OFFSET.toDouble() / LIMIT).toInt()
76 | var size: Int = LIMIT
77 | val pagination = Pagination(page, size)
78 |
79 | if (queryParameters.containsKey("page")) {
80 | page = anyToInt(queryParameters["page"]!!)
81 | pagination.page = if (page >= MIN_LIMIT + 1) page - 1 else MIN_LIMIT
82 | }
83 |
84 | if (queryParameters.containsKey("size")) {
85 | size = anyToInt(queryParameters["size"]!!, "size")
86 | pagination.size = if (size < MAX_LIMIT) size else MAX_LIMIT
87 | }
88 |
89 | return pagination
90 |
91 | }
92 |
93 | /**
94 | * Http router, it receives a class type to return, a request and service to automatically execute and return a response
95 | * @param cls Class return type
96 | * @param request Http Client request
97 | * @param service CRUD service to execute
98 | */
99 | fun defaultRouting(cls: Class, request: Request, service: Service): Any {
100 | val resource: String = getResource(request)
101 | val headers: Map = getHeaders(request)
102 | val pathParameters: Map = getPathParameters(request)
103 | val queryParameters: Map = getQueryStringParameters(request)
104 |
105 | return when((request.input[HTTP_METHOD] as String).toLowerCase()) {
106 | HTTP_GET -> {
107 | when {
108 | resource.endsWith("findOne", true) -> service.findOne(AnonymousUser(), queryParameters)
109 | pathParameters.containsKey("id") -> {
110 | val id = pathParameters["id"]
111 |
112 | when (id) {
113 | is Int -> service.findOne(AnonymousUser(), id)
114 | else -> throw Exception("Id must be an integer")
115 | }
116 | }
117 | else -> {
118 | return service.findAll(AnonymousUser(), queryParameters, getPagination(queryParameters))
119 | }
120 | }
121 | }
122 | HTTP_POST -> {
123 | service.create(AnonymousUser(), getEntity(getRawBody(request), cls))
124 | }
125 | HTTP_PUT -> {
126 | service.update(AnonymousUser(), getEntity(getRawBody(request), cls))
127 | }
128 | HTTP_DELETE -> {
129 | service.delete(AnonymousUser(), getEntity(getRawBody(request), cls).id!!)
130 | }
131 | HTTP_PATCH -> {
132 | service.update(AnonymousUser(), getEntity(getRawBody(request), cls))
133 | }
134 |
135 | else -> {
136 | throw Exception()
137 | }
138 | }
139 | }
140 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/core/dispatchers/Dispatcher.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.core.dispatchers
2 |
3 | /**
4 | * Dispatcher on charge of routing our client request to the correct function
5 | * @param K Key type
6 | * @param T Return object type
7 | */
8 | interface Dispatcher {
9 |
10 | /**
11 | * Function that finds and executes a specific function given a {@link K} unique key
12 | * returning a {@link T} result object
13 | * @param key Unique key to find and execute a function
14 | * @return T
15 | */
16 | fun locate(key: K): T?
17 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/core/dispatchers/RequestDispatcher.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.core.dispatchers
2 |
3 |
4 | import java.io.File
5 | import com.fasterxml.jackson.databind.ObjectMapper
6 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
7 | import com.myblockbuster.core.ApiGatewayRequest
8 | import com.myblockbuster.core.RouterException
9 | import com.myblockbuster.core.Routes
10 | import kotlin.reflect.full.createInstance
11 |
12 | /**
13 | * Request Dispatcher implementation
14 | */
15 | open class RequestDispatcher: Dispatcher {
16 |
17 | @Throws(RouterException::class)
18 | override fun locate(key: ApiGatewayRequest): Any? {
19 | val path = key.input["path"]
20 |
21 | var response: Any? = null
22 | var found: Boolean = false
23 |
24 | for ((regex, function, cls) in ROUTER.routes) {
25 | val match = Regex(regex).matchEntire(path as CharSequence)
26 |
27 | if (match != null) {
28 | // Finds the class based on the absolute class name and runs the function
29 | val kClass = Class.forName(cls).kotlin
30 | val func = kClass.members.find { it.name == function }
31 | response = func?.call(kClass.createInstance(), key)
32 | found = true
33 |
34 | break
35 | }
36 | }
37 |
38 | if (!found)
39 | throw RouterException(path as? String ?: "")
40 |
41 | return response
42 | }
43 |
44 | /**
45 | * Singleton that loads the routes once and keep them on memory
46 | */
47 | companion object BackendRouter {
48 | private val FILE = File(javaClass.classLoader.getResource("routes.yml")!!.file)
49 | val ROUTER: Routes = ObjectMapper(YAMLFactory()).readValue(FILE, Routes::class.java)
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/core/exceptions.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.core
2 |
3 | /**
4 | * Custom exception for our project
5 | * @property code HTTP code that the client is going to receive
6 | * @property message Exception message
7 | * @constructor By default it will reply with a 500 HTTP method
8 | */
9 | abstract class MyException(var code: Int, override var message: String): Exception(message) {
10 | constructor() : this(500, "Internal MyBlockbuster Exception")
11 | }
12 |
13 | /**
14 | * Exception thrown when the body doesn't contain all the required fields
15 | * @property body Input body
16 | */
17 | class InvalidArguments(private var body: String) :
18 | MyException(400, "The entity $body doesn't contain all the required fields")
19 |
20 | /**
21 | * Router Exception (request-dispatcher)
22 | * @property resource The route/resource that failed
23 | * @constructor The default exception is 404 not found exception
24 | */
25 | class RouterException(private var resource: String) :
26 | MyException(404, "The route/resource $resource doesn't exist")
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/core/factories/Factory.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.core.factories
2 |
3 | interface Factory
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/core/factories/ServiceFactory.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.core.factories
2 |
3 | import com.myblockbuster.core.User
4 | import com.myblockbuster.core.services.Service
5 | import com.myblockbuster.movies.Movie
6 | import com.myblockbuster.movies.services.MovieService
7 |
8 | /**
9 | * Creates a Service according to the Entity type to manage
10 | */
11 | class ServiceFactory: Factory {
12 |
13 | fun getService(type: Class): Service {
14 | return when (type) {
15 | Movie::class.java -> MovieService() as Service
16 | else -> throw IllegalArgumentException()
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/core/models.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.core
2 |
3 | import com.amazonaws.services.lambda.runtime.Context
4 | import com.fasterxml.jackson.core.JsonGenerator
5 | import com.fasterxml.jackson.core.JsonProcessingException
6 | import com.fasterxml.jackson.databind.SerializerProvider
7 | import com.fasterxml.jackson.databind.annotation.JsonSerialize
8 | import com.fasterxml.jackson.databind.ser.std.StdSerializer
9 | import org.joda.time.DateTime
10 | import org.joda.time.format.ISODateTimeFormat
11 | import java.io.IOException
12 | import java.io.Serializable
13 | import java.net.URL
14 | import kotlin.math.ceil
15 |
16 | /**
17 | * Generic Model that any body in the future should reply to
18 | */
19 | interface Model: Serializable {
20 | var id: Int?
21 | }
22 |
23 | /**
24 | * In case of no model this is the default model reply
25 | */
26 | class EmptyModel(override var id: Int? = null) : Model
27 |
28 | /**
29 | * In case of error this is the Default Error model to return
30 | */
31 | class ErrorModel(var message: String): Model {
32 | override var id: Int?
33 | get() = null
34 | set(value) {}
35 |
36 | constructor(): this("")
37 | }
38 |
39 | /**
40 | * Represents a client Request
41 | * @property input JSON object with all the request data described in https://serverless.com/framework/docs/providers/aws/events/apigateway/
42 | * @property context Lambda function Metadata
43 | */
44 | interface Request {
45 | var input: Map
46 | var context: Context
47 | }
48 |
49 | /**
50 | * Request Dispatcher route to a concrete function based on a regex
51 | * @property regex Regex that needs to satisfy to route the request
52 | * @property func Function name to be executed
53 | * @property cls ClassPath
54 | * @constructor Creates an empty object with empty values
55 | */
56 | data class Route(var regex: String, var func: String, var cls: String) {
57 | constructor(): this("", "", "")
58 | }
59 |
60 | /**
61 | * List of routes
62 | * @property List of routes
63 | * @constructor emptyList
64 | */
65 | data class Routes(var routes: List) {
66 | constructor(): this(emptyList())
67 | }
68 |
69 | /**
70 | * Represents an APIGateway Request (implements {@link Request})
71 | * @property input JSON object with all the request data described in https://serverless.com/framework/docs/providers/aws/events/apigateway/
72 | * @property context Lambda function Metadata
73 | */
74 | class ApiGatewayRequest(override var input:Map, override var context: Context): Request
75 |
76 |
77 | // ------------------------------------------------------
78 | // User management
79 | // ------------------------------------------------------
80 |
81 | /**
82 | * It's a way to keep a canonical Datetime serializer
83 | */
84 | class DateTimeSerializer @JvmOverloads constructor(t: Class? = null) : StdSerializer(t) {
85 |
86 | @Throws(IOException::class, JsonProcessingException::class)
87 | override fun serialize(value: DateTime, gen: JsonGenerator, arg2: SerializerProvider) {
88 | gen.writeString(formatter.print(value))
89 | }
90 |
91 | private val formatter = ISODateTimeFormat.basicDateTime()
92 | }
93 |
94 | /**
95 | * A base model with some minimum attributes that any entity in the system should have
96 | * @property id Unique ID of that element
97 | * @property createdAt When it was created
98 | * @property updatedAt Last time that the entity changed
99 | */
100 | abstract class BaseModel(override var id: Int?): Model {
101 | constructor(): this(0)
102 |
103 | @JsonSerialize(using = DateTimeSerializer::class)
104 | var createdAt: DateTime? = DateTime()
105 |
106 | @JsonSerialize(using = DateTimeSerializer::class)
107 | var updatedAt: DateTime? = DateTime()
108 | }
109 |
110 | /**
111 | * Basic fields that a User needs
112 | * @property email User email
113 | */
114 | abstract class User: BaseModel() {
115 | open var email: String = ""
116 | }
117 |
118 | /**
119 | * Anonymous User -> User who is not logged into the system
120 | */
121 | class AnonymousUser: User()
122 |
123 | // ------------------------------------------------------
124 | // HTTP and W3C compliant models for HATEOAS/HAL
125 | // ------------------------------------------------------
126 |
127 | /**
128 | * A link relation indicating what is the first, last, previous and next resource
129 | * This is a good practice for self discovery using HAL http://stateless.co/hal_specification.html
130 | * @property value Enum value
131 | */
132 | enum class LinkRel(val value: String) {
133 | NEXT("next"),
134 | FIRST("first"),
135 | LAST("last"),
136 | SELF("self")
137 | }
138 |
139 | /**
140 | * Resource link
141 | * @property rel Type of link
142 | * @property url URL String
143 | */
144 | data class Link(var rel: LinkRel, var url: URL)
145 |
146 | /**
147 | * Metadata of an specific page, in case of HAL it's always good practice to return context data
148 | * @param limit Max amount of objects to show per page (like SQL LIMIT)
149 | * @param offset From which element we start to count
150 | * @param count Total elements
151 | * @property totalPages Total pages that it's basically the ceil(COUNT/LIMIT)
152 | * @property pageNumber Current page that it's basically the ceil(OFFSET+1/LIMIT)
153 | * @property totalElements It's equals to COUNT
154 | */
155 | class PageMetadata(limit: Int, offset: Int, count: Int) {
156 | val totalPages: Int = ceil(count.toDouble() / limit.toDouble()).toInt()
157 | val pageNumber: Int = ceil((offset.toDouble() + 1) / limit.toDouble()).toInt()
158 | val totalElements: Int = count
159 |
160 | val first: Boolean
161 | get() = pageNumber == 1
162 |
163 | val last: Boolean
164 | get() = pageNumber == totalPages
165 |
166 | override fun toString(): String {
167 | return "PageMetadata(totalPages=$totalPages, pageNumber=$pageNumber, " +
168 | "totalElements=$totalElements, first=$first, last=$last)"
169 | }
170 | }
171 |
172 | /**
173 | * In case of multiple elements we reply with a page, that includes the data and metadata of a set of objects
174 | * @param sort Map of values to sort (based on the URL params, that means that we don't include ?page & ?size)
175 | * @param limit Max amount of objects to show per page (like SQL LIMIT)
176 | * @param offset From which element we start to count
177 | * @property content List of objects
178 | * @property links HAL links
179 | * @property sort Way to sort our results based on URL params
180 | * @property metadata HAL metadata
181 | */
182 | class Page(sort: Map, limit: Int, offset: Int, count: Int,
183 | var content: List, var links: List = emptyList()): Model {
184 |
185 | override var id: Int?
186 | get() = null
187 | set(value) {}
188 |
189 | var sort: Map = sort
190 | get() = field.minus(arrayOf("page", "size"))
191 |
192 | val metadata: PageMetadata = PageMetadata(limit, offset, count)
193 |
194 |
195 | override fun toString(): String {
196 | return "Page(content=$content, sort=$sort, links=$links, metadata=$metadata)"
197 | }
198 | }
199 |
200 | /**
201 | * Desired pagination
202 | * @property page Page Number to present
203 | * @property size Size of the pages
204 | */
205 | data class Pagination(var page: Int, var size: Int)
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/core/services/Service.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.core.services
2 |
3 | import com.myblockbuster.core.Page
4 | import com.myblockbuster.core.Pagination
5 |
6 | /**
7 | * Service that exposes the capabilities of a {@link T} element
8 | * @param Natural Key type
9 | * @param Element type
10 | * @param Filter type
11 | * @param User permissions
12 | */
13 | interface Service {
14 |
15 | /**
16 | * Creates a [T] in the system
17 | * @param user [U] User who is requesting (to verify permissions)
18 | * @param element [T] that is going to be saved
19 | * @return element with the saved status
20 | */
21 | fun create(user: U, element: T): T
22 |
23 | /**
24 | * Find a set of [T] by a given set of optional parameters
25 | * @param user [U] User who is requesting (to verify permissions)
26 | * @param filters Optional parameters
27 | * @param pagination How to paginate the result
28 | * @return list of [T]
29 | */
30 | fun findAll(user: U, filters: Map = mapOf( "order" to "creationDate" ),
31 | pagination: Pagination = Pagination(0, 50)): Page
32 |
33 | /**
34 | * Finds one [T] by the unique ID
35 | * @param user [U] User who is requesting (to verify permissions)
36 | * @param id Unique id
37 | * @return [T] that has that ID
38 | */
39 | fun findOne(user: U, id: Int): T
40 |
41 | /**
42 | * Finds one [T] by an unique natural [K] key
43 | * @param user [U] User who is requesting (to verify permissions)
44 | * @param filters Set of filters that will return a unique value
45 | * @return [T] that has that [Any] natural key
46 | */
47 | fun findOne(user: U, filters: Map = emptyMap()): T
48 |
49 | /**
50 | * Updates a [T]
51 | * @param user [U] User who is requesting (to verify permissions)
52 | * @param element [T] that is going to be updated
53 | * @return updated element
54 | */
55 | fun update(user: U, element: T): T
56 |
57 | /**
58 | * Deletes a [T] given a unique ID
59 | * @param user [U] User who is requesting (to verify permissions)
60 | * @param id Unique ID of the [T]
61 | */
62 | fun delete(user: U, id: Int)
63 |
64 | /**
65 | * Returns the amount or [T] entities in the system
66 | * @param user [U] User who is requesting (to verify permissions)
67 | * @param filters Set of filters
68 | * @return list of [T]
69 | */
70 | fun count(user: U, filters: Map = emptyMap()): Int
71 |
72 | /**
73 | * Verifies if a entity with a specific ID exists
74 | * @param user [U] User who is requesting (to verify permissions)
75 | * @param id Unique id
76 | * @return [Boolean] value indicating true if exists or false if not
77 | */
78 | fun exists(user: U, id: Int): Boolean
79 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/movies/controllers/MovieController.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.movies.controllers
2 |
3 | import com.myblockbuster.core.Request
4 | import com.myblockbuster.core.User
5 | import com.myblockbuster.core.controllers.Controller
6 | import com.myblockbuster.core.factories.ServiceFactory
7 | import com.myblockbuster.core.services.Service
8 | import com.myblockbuster.movies.Movie
9 |
10 | class MovieController: Controller {
11 |
12 | fun movie(request: Request?) : Any {
13 | val service: Service = ServiceFactory().getService(Movie::class.java)
14 | return defaultRouting(Movie::class.java, request!!, service)
15 | }
16 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/movies/exceptions.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.movies
2 |
3 | import com.myblockbuster.core.MyException
4 |
5 | class MovieAlreadyExistsException(code: Int = 400, message: String = "Movie Already Exists") : MyException(code, message)
6 |
7 | class MovieNotExistsException(code: Int = 404, message: String = "Movie Doesn't Exists") : MyException(code, message)
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/movies/models.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.movies
2 |
3 | import com.myblockbuster.core.BaseModel
4 |
5 | data class Person(var name: String, var surname: String) {
6 | constructor() : this("", "")
7 | }
8 |
9 | data class Movie(var title: String, var rate: Double, var language: String, var director: Person,
10 | var cast: List, var code: String, override var id: Int?): BaseModel() {
11 | constructor(): this("", 0.0, "EN", Person(), listOf(Person()), "", -1)
12 | }
--------------------------------------------------------------------------------
/src/main/kotlin/com/myblockbuster/movies/services/MovieService.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster.movies.services
2 |
3 | import com.myblockbuster.core.Page
4 | import com.myblockbuster.core.Pagination
5 | import com.myblockbuster.core.User
6 | import com.myblockbuster.core.services.Service
7 | import com.myblockbuster.movies.Movie
8 | import com.myblockbuster.movies.MovieAlreadyExistsException
9 | import com.myblockbuster.movies.MovieNotExistsException
10 | import kotlin.math.min
11 |
12 | class MovieService: Service {
13 |
14 | // This is because we don't have a persistence layer yet
15 | // Part 6 will explain that
16 | val elements: MutableList = ArrayList()
17 |
18 | override fun create(user: User, element: Movie): Movie {
19 | if (elements.find { it.code == element.code } == null)
20 | elements.add(element)
21 | else
22 | throw MovieAlreadyExistsException()
23 |
24 | return element
25 | }
26 |
27 | override fun findAll(user: User, filters: Map, pagination: Pagination): Page {
28 | val offset = min(pagination.page * pagination.size, elements.size - 1)
29 | val toIndex = min(offset + pagination.size, elements.size - 1)
30 | return Page(filters, pagination.size, offset, elements.size,
31 | if (elements.isEmpty()) elements else elements.subList(offset, toIndex))
32 | }
33 |
34 | override fun findOne(user: User, id: Int): Movie {
35 | val movie: Movie? = elements.find { it.id == id}
36 | if (movie != null)
37 | return movie
38 | else
39 | throw MovieNotExistsException()
40 | }
41 |
42 | override fun findOne(user: User, filters: Map): Movie {
43 | TODO("not implemented")
44 | }
45 |
46 | override fun update(user: User, element: Movie): Movie {
47 | val movie = findOne(user, element.id!!)
48 | movie.cast = element.cast
49 | movie.code = element.code
50 | movie.director = element.director
51 | movie.language = element.language
52 | movie.rate = element.rate
53 | movie.title = element.title
54 |
55 | return movie
56 | }
57 |
58 | override fun delete(user: User, id: Int) {
59 | val movie = findOne(user, id)
60 | elements.remove(movie)
61 | }
62 |
63 | override fun count(user: User, filters: Map): Int {
64 | return elements.size
65 | }
66 |
67 | override fun exists(user: User, id: Int): Boolean {
68 | return elements.find { it.id == id} != null
69 | }
70 |
71 | }
--------------------------------------------------------------------------------
/src/main/resources/helloEvent.json:
--------------------------------------------------------------------------------
1 | {
2 | "event": "hello"
3 | }
--------------------------------------------------------------------------------
/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | %d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/resources/routes.yml:
--------------------------------------------------------------------------------
1 | routes:
2 | # =========================
3 | # Movies Microservice
4 | # =========================
5 |
6 | - regex: '^/movie(/*+)?$'
7 | cls: com.myblockbuster.movies.controllers.MovieController
8 | func: movie
9 |
10 | # =========================
11 | # User Microservice
12 | # =========================
13 |
14 | - regex: '^/login(/)?$'
15 | cls: com.myblockbuster.users.controllers.UserController
16 | func: login
17 | - regex: '^/logout(/)?$'
18 | cls: com.myblockbuster.users.controllers.UserController
19 | func: logout
20 | - regex: '^/signup(/)?$'
21 | cls: com.myblockbuster.users.controllers.UserController
22 | func: signup
23 |
24 | # =========================
25 | # Geolocation Microservice
26 | # =========================
27 |
28 | - regex: '^/location/country(/*+)?$'
29 | cls: com.myblockbuster.geolocation.controllers.LocationController
30 | func: country
31 | - regex: '^/location/region(/*+)?$'
32 | cls: com.myblockbuster.geolocation.controllers.LocationController
33 | func: region
34 | - regex: '^/location/city(/*+)?$'
35 | cls: com.myblockbuster.geolocation.controllers.LocationController
36 | func: region
--------------------------------------------------------------------------------
/src/test/kotlin/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/juancho088/using-kotlin-serverless-architecture-aws-lambda/57fc74e25f7e9c7158697cf83384a2d8da4e4b95/src/test/kotlin/.gitkeep
--------------------------------------------------------------------------------
/src/test/kotlin/com/myblockbuster/TestHandler.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster
2 |
3 | import com.nhaarman.mockito_kotlin.any
4 | import com.nhaarman.mockito_kotlin.whenever
5 | import org.jetbrains.spek.api.Spek
6 | import org.jetbrains.spek.api.dsl.given
7 | import org.jetbrains.spek.api.dsl.it
8 | import org.jetbrains.spek.api.dsl.on
9 | import org.junit.Assert.assertEquals
10 | import org.mockito.Mockito
11 | import com.amazonaws.services.lambda.runtime.Context
12 | import com.myblockbuster.core.EmptyModel
13 | import com.myblockbuster.core.RouterException
14 | import com.myblockbuster.core.dispatchers.RequestDispatcher
15 |
16 | class TestHandler: Spek({
17 | given("a new event") {
18 | var handler: Handler? = null
19 | var context: Context? = null
20 | var dispatcher: RequestDispatcher? = null
21 | var map: Map? = null
22 |
23 | beforeEachTest {
24 | handler = Handler()
25 | context = Mockito.mock(Context::class.java)
26 | map = mapOf("path" to "test")
27 | dispatcher = Mockito.mock(RequestDispatcher::class.java)
28 | handler?.requestDispatcher = dispatcher!!
29 |
30 | }
31 | on("correct path") {
32 | it("should return a status code of 204 if the response body is empty") {
33 | whenever(dispatcher?.locate(any())).thenReturn(EmptyModel())
34 | val response = context?.let { handler?.handleRequest(map as Map, it) }
35 | assertEquals(204, response?.statusCode)
36 | }
37 | it("should return a status code of 200 if the response body is not empty") {
38 | whenever(dispatcher?.locate(any())).thenReturn(TestModel())
39 | val response = context?.let { handler?.handleRequest(map as Map, it) }
40 | assertEquals(200, response?.statusCode)
41 | }
42 |
43 | }
44 | on("non-existent path") {
45 | it("should return a status code of 404") {
46 | whenever(dispatcher?.locate(any())).thenThrow(RouterException(""))
47 | val response = context?.let { handler?.handleRequest(map as Map, it) }
48 | assertEquals(404, response?.statusCode)
49 | }
50 | }
51 | }
52 | })
--------------------------------------------------------------------------------
/src/test/kotlin/com/myblockbuster/models.kt:
--------------------------------------------------------------------------------
1 | package com.myblockbuster
2 |
3 | import com.myblockbuster.core.BaseModel
4 |
5 |
6 | class TestModel(var a: String, var b: String, var c: Int, var d: Double): BaseModel() {
7 | constructor() : this("", "", Int.MAX_VALUE, Double.MAX_VALUE)
8 | }
9 |
10 | class TestScenario(var elements: Array) {
11 |
12 | }
--------------------------------------------------------------------------------
/src/test/resources/eventMovieGET.json:
--------------------------------------------------------------------------------
1 | {
2 | "resource": "/movies/{id}",
3 | "path": "/movies",
4 | "httpMethod": "GET",
5 | "headers": {
6 | "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
7 | "Accept-Encoding": "gzip, deflate, br",
8 | "Accept-Language": "en-GB,en-US;q=0.8,en;q=0.6,zh-CN;q=0.4",
9 | "cache-control": "max-age=0",
10 | "CloudFront-Forwarded-Proto": "https",
11 | "CloudFront-Is-Desktop-Viewer": "true",
12 | "CloudFront-Is-Mobile-Viewer": "false",
13 | "CloudFront-Is-SmartTV-Viewer": "false",
14 | "CloudFront-Is-Tablet-Viewer": "false",
15 | "CloudFront-Viewer-Country": "GB",
16 | "content-type": "application/x-www-form-urlencoded",
17 | "Host": "j3ap25j034.execute-api.eu-west-2.amazonaws.com",
18 | "origin": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com",
19 | "Referer": "https://j3ap25j034.execute-api.eu-west-2.amazonaws.com/dev/",
20 | "upgrade-insecure-requests": "1",
21 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
22 | "Via": "2.0 a3650115c5e21e2b5d133ce84464bea3.cloudfront.net (CloudFront)",
23 | "X-Amz-Cf-Id": "0nDeiXnReyHYCkv8cc150MWCFCLFPbJoTs1mexDuKe2WJwK5ANgv2A==",
24 | "X-Amzn-Trace-Id": "Root=1-597079de-75fec8453f6fd4812414a4cd",
25 | "X-Forwarded-For": "50.129.117.14, 50.112.234.94",
26 | "X-Forwarded-Port": "443",
27 | "X-Forwarded-Proto": "https"
28 | },
29 | "queryStringParameters": null,
30 | "pathParameters": null,
31 | "stageVariables": null,
32 | "requestContext": {
33 | "path": "/dev/",
34 | "accountId": "125002137610",
35 | "resourceId": "qdolsr1yhk",
36 | "stage": "dev",
37 | "requestId": "0f2431a2-6d2f-11e7-b75152aa497861",
38 | "identity": {
39 | "cognitoIdentityPoolId": null,
40 | "accountId": null,
41 | "cognitoIdentityId": null,
42 | "caller": null,
43 | "apiKey": "",
44 | "sourceIp": "50.129.117.14",
45 | "accessKey": null,
46 | "cognitoAuthenticationType": null,
47 | "cognitoAuthenticationProvider": null,
48 | "userArn": null,
49 | "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
50 | "user": null
51 | },
52 | "resourcePath": "/movies/{id}",
53 | "httpMethod": "GET",
54 | "apiId": "j3azlsj0c4"
55 | },
56 | "body": null,
57 | "isBase64Encoded": false
58 | }
--------------------------------------------------------------------------------