16
16
version : " 3.9"
17
17
services :
18
18
spring-native-aws-lambda-function-infra :
19
- image : ghcr.io/ muhamadto/spring-native-amazonlinux2-builder:21-amazonlinux2-awscliv2
19
+ image : muhamadto/spring-native-amazonlinux2-builder:21-amazonlinux2-awscliv2
20
20
volumes :
21
21
- ./:/app
22
22
- ${M2_REPO}:/home/worker/.m2
23
23
working_dir : /app
24
24
user : worker
25
25
environment :
26
- SPRING_MAIN_WEBAPPLICATIONTYPE : servlet
27
26
AWS_DEFAULT_REGION : ap-southeast-2
28
27
AWS_REGION : ap-southeast-2
29
28
AWS_ACCESS_KEY_ID : local
30
29
AWS_SECRET_ACCESS_KEY : local
31
30
AWS_ENDPOINT_URL : http://localstack:4566
31
+ BUILD_ARTIFACT : ' true'
32
+ FUNCTION_NAME : spring-native-aws-lambda-function
33
+ STAGE : compose
32
34
MAVEN_OPTS : |
33
35
-DskipTests=true
34
36
-Dcheckstyle.skip=true
@@ -43,32 +45,41 @@ services:
43
45
- -c
44
46
command : |
45
47
'
48
+ function package_spring_native_lambda() {
49
+ if [ "$$BUILD_ARTIFACT" = "true" ]; then
50
+ ./mvnw -ntp clean -Pnative -DskipTests native:compile package -pl "$$FUNCTION_NAME"
51
+ else
52
+ print_info_message "plain" "BUILD_ARTIFACT environment variable is not set. Skipping Maven build."
53
+ fi
54
+ }
55
+
46
56
aws --version &&
47
57
48
58
source /usr/local/bin/awscliv2-util/aws &&
49
59
50
- print_info_message "block" "Creating 'spring-native-aws-lambda-function '" &&
60
+ print_info_message "block" "Creating '"$$FUNCTION_NAME" '" &&
51
61
52
62
print_info_message "divider" "Package GraalVM function" &&
53
-
54
- ./mvnw -ntp clean -Pnative -DskipTests native:compile package -pl spring-native-aws-lambda-function &&
63
+
64
+ package_spring_native_lambda &&
55
65
56
66
print_info_message "divider" "Creating LAMBDA function" &&
57
- lambda_create_function lambda-FUNCTION provided.al2023 512 ./spring-native-aws-lambda-function /target/spring -native-aws-lambda-function-native- zip.zip spring-native-aws-lambda-function &&
58
- lambda_wait_for_function lambda-FUNCTION &&
67
+ lambda_create_function "$$FUNCTION_NAME" provided.al2023 512 ./"$$FUNCTION_NAME" /target/"$$FUNCTION_NAME" -native-zip.zip "$$FUNCTION_NAME" &&
68
+ lambda_wait_for_function "$$FUNCTION_NAME" &&
59
69
lambda_list_functions &&
60
-
70
+ LAMBDA_ARN="$(lambda_get_function_arn "$$FUNCTION_NAME")" &&
71
+
61
72
print_info_message "divider" "Creating API Gateway" &&
62
73
REST_API_ID="$(apigateway_create_restApi "somerestapiname")" &&
63
74
RESOURCE_ID="$(apigateway_create_resource "$$REST_API_ID" "somePathId")"
64
75
apigateway_create_method "$$REST_API_ID" "$$RESOURCE_ID" "POST" &&
65
- apigateway_create_lambda_integration "$$REST_API_ID" "$$RESOURCE_ID" "POST" "arn:aws:apigateway: ap-southeast-2:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-2:000000000000:function:lambda-FUNCTION/invocations " &&
66
- apigateway_create_deployment "$$REST_API_ID" "test " &&
67
- --rest-api-id &&
76
+ apigateway_create_lambda_integration "$$REST_API_ID" "$$RESOURCE_ID" "POST" "$$LAMBDA_ARN" " ap-southeast-2" &&
77
+ apigateway_create_deployment "$$REST_API_ID" "$$STAGE " &&
78
+ apigateway_list_restapis &&
68
79
69
- print_info_message "plain" "Endpoint available at: http://localhost:4566/restapis/$$REST_API_ID/test /_user_request_/test " &&
80
+ print_info_message "plain" "Endpoint available at: http://localhost:4566/restapis/$$REST_API_ID/$$STAGE /_user_request_/somePathId " &&
70
81
71
- print_info_message "block" "Successfully creating 'spring-native-aws-lambda-function '"
82
+ print_info_message "block" "Successfully creating '"$$FUNCTION_NAME" '"
72
83
'
73
84
depends_on :
74
85
- localstack
0 commit comments