Skip to content

Commit

Permalink
Fixed apigateway to lambda integration
Browse files Browse the repository at this point in the history
Signed-off-by: matto <[email protected]>
  • Loading branch information
muhamadto committed Jan 10, 2024
1 parent 38f98c3 commit a88125c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
ENV: ${{ env.ENV }}
COST_CENTRE: ${{ env.COST_CENTRE }}
run: ./mvnw -ntp -Pnative clean package -DskipTests
run: |
./mvnw -ntp clean verify -DskipTests
./mvnw -ntp clean -Pnative -DskipTests native:compile package -pl spring-native-aws-lambda-function
- name: cdk diff
uses: muhamadto/aws-cdk-github-actions@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $ ./mvnw -ntp clean verify -U
```
2. Make a call
```shell
$ curl --location --request POST 'http://localhost:4566/restapis/<restApiId>/test/_user_request_/test' \
$ curl --location --request POST 'http://localhost:4566/restapis/<restApiId>/compose/_user_request_/somePathId' \
--header 'Content-Type: application/json' \
--data-raw '{
"body": "{ \"name\": \"CoffeeBeans\" }"
Expand Down
37 changes: 24 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
version: "3.9"
services:
spring-native-aws-lambda-function-infra:
image: ghcr.io/muhamadto/spring-native-amazonlinux2-builder:21-amazonlinux2-awscliv2
image: muhamadto/spring-native-amazonlinux2-builder:21-amazonlinux2-awscliv2
volumes:
- ./:/app
- ${M2_REPO}:/home/worker/.m2
working_dir: /app
user: worker
environment:
SPRING_MAIN_WEBAPPLICATIONTYPE: servlet
AWS_DEFAULT_REGION: ap-southeast-2
AWS_REGION: ap-southeast-2
AWS_ACCESS_KEY_ID: local
AWS_SECRET_ACCESS_KEY: local
AWS_ENDPOINT_URL: http://localstack:4566
BUILD_ARTIFACT: 'true'
FUNCTION_NAME: spring-native-aws-lambda-function
STAGE: compose
MAVEN_OPTS: |
-DskipTests=true
-Dcheckstyle.skip=true
Expand All @@ -43,32 +45,41 @@ services:
- -c
command: |
'
function package_spring_native_lambda() {
if [ "$$BUILD_ARTIFACT" = "true" ]; then
./mvnw -ntp clean -Pnative -DskipTests native:compile package -pl "$$FUNCTION_NAME"
else
print_info_message "plain" "BUILD_ARTIFACT environment variable is not set. Skipping Maven build."
fi
}
aws --version &&
source /usr/local/bin/awscliv2-util/aws &&
print_info_message "block" "Creating 'spring-native-aws-lambda-function'" &&
print_info_message "block" "Creating '"$$FUNCTION_NAME"'" &&
print_info_message "divider" "Package GraalVM function" &&
./mvnw -ntp clean -Pnative -DskipTests native:compile package -pl spring-native-aws-lambda-function &&
package_spring_native_lambda &&
print_info_message "divider" "Creating LAMBDA function" &&
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 &&
lambda_wait_for_function lambda-FUNCTION &&
lambda_create_function "$$FUNCTION_NAME" provided.al2023 512 ./"$$FUNCTION_NAME"/target/"$$FUNCTION_NAME"-native-zip.zip "$$FUNCTION_NAME" &&
lambda_wait_for_function "$$FUNCTION_NAME" &&
lambda_list_functions &&
LAMBDA_ARN="$(lambda_get_function_arn "$$FUNCTION_NAME")" &&
print_info_message "divider" "Creating API Gateway" &&
REST_API_ID="$(apigateway_create_restApi "somerestapiname")" &&
RESOURCE_ID="$(apigateway_create_resource "$$REST_API_ID" "somePathId")"
apigateway_create_method "$$REST_API_ID" "$$RESOURCE_ID" "POST" &&
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" &&
apigateway_create_deployment "$$REST_API_ID" "test" &&
--rest-api-id &&
apigateway_create_lambda_integration "$$REST_API_ID" "$$RESOURCE_ID" "POST" "$$LAMBDA_ARN" "ap-southeast-2" &&
apigateway_create_deployment "$$REST_API_ID" "$$STAGE" &&
apigateway_list_restapis &&
print_info_message "plain" "Endpoint available at: http://localhost:4566/restapis/$$REST_API_ID/test/_user_request_/test" &&
print_info_message "plain" "Endpoint available at: http://localhost:4566/restapis/$$REST_API_ID/$$STAGE/_user_request_/somePathId" &&
print_info_message "block" "Successfully creating 'spring-native-aws-lambda-function'"
print_info_message "block" "Successfully creating '"$$FUNCTION_NAME"'"
'
depends_on:
- localstack
Expand Down

0 comments on commit a88125c

Please sign in to comment.