Skip to content

Commit a88125c

Browse files
committed
Fixed apigateway to lambda integration
Signed-off-by: matto <muhamadto@gmail.com>
1 parent 38f98c3 commit a88125c

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ jobs:
5757
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
5858
ENV: ${{ env.ENV }}
5959
COST_CENTRE: ${{ env.COST_CENTRE }}
60-
run: ./mvnw -ntp -Pnative clean package -DskipTests
60+
run: |
61+
./mvnw -ntp clean verify -DskipTests
62+
./mvnw -ntp clean -Pnative -DskipTests native:compile package -pl spring-native-aws-lambda-function
6163
- name: cdk diff
6264
uses: muhamadto/aws-cdk-github-actions@v5
6365
with:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $ ./mvnw -ntp clean verify -U
3535
```
3636
2. Make a call
3737
```shell
38-
$ curl --location --request POST 'http://localhost:4566/restapis/<restApiId>/test/_user_request_/test' \
38+
$ curl --location --request POST 'http://localhost:4566/restapis/<restApiId>/compose/_user_request_/somePathId' \
3939
--header 'Content-Type: application/json' \
4040
--data-raw '{
4141
"body": "{ \"name\": \"CoffeeBeans\" }"

docker-compose.yml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@
1616
version: "3.9"
1717
services:
1818
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
2020
volumes:
2121
- ./:/app
2222
- ${M2_REPO}:/home/worker/.m2
2323
working_dir: /app
2424
user: worker
2525
environment:
26-
SPRING_MAIN_WEBAPPLICATIONTYPE: servlet
2726
AWS_DEFAULT_REGION: ap-southeast-2
2827
AWS_REGION: ap-southeast-2
2928
AWS_ACCESS_KEY_ID: local
3029
AWS_SECRET_ACCESS_KEY: local
3130
AWS_ENDPOINT_URL: http://localstack:4566
31+
BUILD_ARTIFACT: 'true'
32+
FUNCTION_NAME: spring-native-aws-lambda-function
33+
STAGE: compose
3234
MAVEN_OPTS: |
3335
-DskipTests=true
3436
-Dcheckstyle.skip=true
@@ -43,32 +45,41 @@ services:
4345
- -c
4446
command: |
4547
'
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+
4656
aws --version &&
4757
4858
source /usr/local/bin/awscliv2-util/aws &&
4959
50-
print_info_message "block" "Creating 'spring-native-aws-lambda-function'" &&
60+
print_info_message "block" "Creating '"$$FUNCTION_NAME"'" &&
5161
5262
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 &&
5565
5666
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" &&
5969
lambda_list_functions &&
60-
70+
LAMBDA_ARN="$(lambda_get_function_arn "$$FUNCTION_NAME")" &&
71+
6172
print_info_message "divider" "Creating API Gateway" &&
6273
REST_API_ID="$(apigateway_create_restApi "somerestapiname")" &&
6374
RESOURCE_ID="$(apigateway_create_resource "$$REST_API_ID" "somePathId")"
6475
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 &&
6879
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" &&
7081
71-
print_info_message "block" "Successfully creating 'spring-native-aws-lambda-function'"
82+
print_info_message "block" "Successfully creating '"$$FUNCTION_NAME"'"
7283
'
7384
depends_on:
7485
- localstack

0 commit comments

Comments
 (0)