Skip to content

Commit

Permalink
Use apigateway functions from ghcr.io/muhamadto/spring-native-amazonl…
Browse files Browse the repository at this point in the history
…inux2-builder:21-amazonlinux2-awscliv2

Signed-off-by: matto <muhamadto@gmail.com>
  • Loading branch information
muhamadto committed Dec 29, 2023
1 parent c96de34 commit 4211b44
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.idea/
badges/
**/target/
cdk.out/
volume/
.gitignore
CODE_OF_CONDUCT.md
HELP.md
Expand Down
10 changes: 4 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
target/
!spring-native-aws-lambda-function/.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
**/target/
cdk.out/
volume/
**/maven-wrapper.jar

### STS ###
.apt_generated
Expand Down Expand Up @@ -30,5 +30,3 @@ build/

### VS Code ###
.vscode/

**/maven-wrapper.jar
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ $ ./mvnw -ntp clean verify -U
```

#### Using `mvnw`
1. Set `spring.main.web-application-type` to `servlet` for local development
2. Run the following commands

1. Run the following commands
```shell
$ ./mvnw -ntp clean package -U -Pnative -pl spring-native-aws-lambda-function
$ export SPRING_PROFILES_ACTIVE=local
$ ./mvnw -ntp clean package -U -Pnative -DskipTests native:compile -pl spring-native-aws-lambda-function
$ ./spring-native-aws-lambda-function/target/spring-native-aws-lambda-function
```
The service starts in less than 100 ms
Expand All @@ -76,8 +77,8 @@ $ ./mvnw -ntp clean verify -U
$ curl --location --request POST 'http://localhost:8080' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "CoffeeBeans"
}'
"body": "{ \"name\": \"CoffeeBeans\" }"
}'
```
The service responds
```json
Expand Down
20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
version: "3.9"
services:
spring-native-aws-lambda-function-infra:
image: muhamadto/spring-native-amazonlinux2-builder:21-amazonlinux2-awscliv2
image: ghcr.io/muhamadto/spring-native-amazonlinux2-builder:21-amazonlinux2-awscliv2
volumes:
- ./:/app
- ${M2_REPO}:/home/worker/.m2
Expand Down Expand Up @@ -51,22 +51,22 @@ services:
print_info_message "divider" "Package GraalVM function" &&
./mvnw -ntp clean package -U -Pnative -pl spring-native-aws-lambda-function &&
./mvnw -ntp clean package -U -Pnative -DskipTests native:compile -pl spring-native-aws-lambda-function &&
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_list_functions &&
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" &&
apigateway_list_restapis &&
REST_API_ID="$(aws apigateway --endpoint-url="http://localstack:4566" create-rest-api --name 'someapigateway' --query 'id' --output text)" &&
ROOT_RESOURCE_ID=$(aws apigateway --endpoint-url="http://localstack:4566" get-resources --rest-api-id "$$REST_API_ID" --query 'items[0].id' --output text)
RESOURCE_ID=$(aws apigateway --endpoint-url="http://localstack:4566" create-resource --rest-api-id $$REST_API_ID --parent-id $$ROOT_RESOURCE_ID --path-part '{somethingPathId}' --query 'id' --output text)
aws apigateway --endpoint-url="http://localstack:4566" put-method --rest-api-id $$REST_API_ID --resource-id $$RESOURCE_ID --http-method POST --request-parameters 'method.request.path.somethingPathId=true' --authorization-type 'NONE' &&
aws apigateway --endpoint-url="http://localstack:4566" put-integration --rest-api-id $$REST_API_ID --resource-id $$RESOURCE_ID --http-method POST --type AWS_PROXY --integration-http-method POST --uri arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-2:000000000000:function:lambda-FUNCTION/invocations --passthrough-behavior WHEN_NO_MATCH &&
aws apigateway --endpoint-url="http://localstack:4566" create-deployment --rest-api-id $$REST_API_ID --stage-name test &&
print_info_message "plain" "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/test/_user_request_/test" &&
print_info_message "block" "Successfully creating 'spring-native-aws-lambda-function'"
'
Expand Down
9 changes: 0 additions & 9 deletions spring-native-aws-lambda-function/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,6 @@
<buildArg>-H:+ReportExceptionStackTraces</buildArg>
</buildArgs>
</configuration>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down

0 comments on commit 4211b44

Please sign in to comment.