Skip to content

Commit

Permalink
use sandpiper infra
Browse files Browse the repository at this point in the history
  • Loading branch information
muhamadto committed Mar 27, 2024
1 parent 0b97b1f commit 25396ad
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 40 deletions.
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ $ ./mvnw -ntp clean verify -U
```
The service responds
```json
[
{
"name": "CoffeeBeans",
"saved": true
}
]
{
"id": "production1234someapp",
"env": "production",
"costCentre": "1234",
"applicationName": "some-app",
"items": {
"GITHUB_TOKEN": "WOAH",
"AWS_ACCESS_KEY_ID": "OMG",
"AWS_SECRET_ACCESS_KEY": "OH NO"
}
}
```

#### Using `mvnw`
Expand Down Expand Up @@ -81,16 +86,6 @@ $ ./mvnw -ntp clean verify -U
"body": "{ \"env\": \"production\", \"costCentre\": \"1234\", \"applicationName\": \"some-app\", \"items\": { \"GITHUB_TOKEN\": \"WOAH\", \"AWS_ACCESS_KEY_ID\": \"OMG\", \"AWS_SECRET_ACCESS_KEY\": \"OH NO\" } }"
}'
```
```shell
curl --location --request POST 'http://localhost:8080' \
--header 'Content-Type: application/json' \
--data-raw '{
"httpMethod": "GET",
"pathParameters": {
"proxy": "production-1234-someapp"
}
}'
```

The service responds
```json
Expand Down Expand Up @@ -451,8 +446,11 @@ Now that the setup is done you can deploy to AWS.
the [github action](.github/workflows/release.yml) will start and a deployment to AWS
environment.
2. Test via curl
```shell
$ curl --location --request POST 'https://lmk0qo0xrl.execute-api.ap-southeast-2.amazonaws.com/dev/' \

POST

```shell
$ curl --location --request POST 'https://{apiid}.execute-api.ap-southeast-2.amazonaws.com/dev/' \
--header 'Content-Type: application/json' \
--data-raw '{
"env": "production",
Expand All @@ -464,6 +462,12 @@ Now that the setup is done you can deploy to AWS.
"AWS_SECRET_ACCESS_KEY": "OH NO"
}
}'
```
```

GET

```shell
curl --request GET 'https://{apiid}.execute-api.ap-southeast-2.amazonaws.com/dev/production-1234-someapp'
```
3. Et voila! It runs with 500 ms for cold start.

2 changes: 1 addition & 1 deletion cdk.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"app": "./mvnw --settings /Users/muhammad/.m2/settings-nonqantas.xml exec:java -pl spring-native-aws-service-infra -Dexec.mainClass=com.coffeebeans.springnativeawslambda.infra.Application",
"app": "./mvnw exec:java -pl spring-native-aws-service-infra -Dexec.mainClass=com.coffeebeans.springnativeawslambda.infra.Application",
"context": {
"@aws-cdk/core:bootstrapQualifier": "cbcore"
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ services:
'
function package_spring_native_function() {
if [ "$$BUILD_ARTIFACT" = "true" ]; then
./mvnw -ntp clean -Pnative -DskipTests native:compile package -pl "$$FUNCTION_NAME" --settings /home/worker/.m2/settings-nonqantas.xml
./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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@
import io.sadpipers.cdk.type.KebabCaseString;
import io.sadpipers.cdk.type.SafeString;
import io.sandpipers.cdk.core.AbstractEnvironment;
import io.sandpipers.cdk.core.construct.BaseStack;
import io.sandpipers.cdk.core.construct.dynamodb.TableV2;
import io.sandpipers.cdk.core.construct.dynamodb.TableV2.TableProps;
import io.sandpipers.cdk.core.construct.lambda.CustomRuntime2023Function;
import io.sandpipers.cdk.core.construct.lambda.CustomRuntime2023Function.CustomRuntime2023FunctionProps;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import software.amazon.awscdk.DefaultStackSynthesizer;
import software.amazon.awscdk.Duration;
import software.amazon.awscdk.RemovalPolicy;
import software.amazon.awscdk.Stack;
import software.amazon.awscdk.StackProps;
import software.amazon.awscdk.services.apigateway.LambdaRestApi;
import software.amazon.awscdk.services.apigateway.Resource;
import software.amazon.awscdk.services.apigateway.StageOptions;
Expand All @@ -51,7 +49,7 @@
import static software.amazon.awscdk.services.iam.ManagedPolicy.fromAwsManagedPolicyName;
import static software.amazon.awscdk.services.lambda.Code.fromAsset;

public class SpringNativeAwsFunctionStack extends Stack {
public class SpringNativeAwsFunctionStack extends BaseStack {

private static final int LAMBDA_FUNCTION_TIMEOUT_IN_SECONDS = 3;
private static final int LAMBDA_FUNCTION_MEMORY_SIZE = 512;
Expand All @@ -63,8 +61,7 @@ public SpringNativeAwsFunctionStack(@NotNull final Application app,
@NotNull final AbstractEnvironment environment,
@NotBlank final String lambdaCodePath,
@NotBlank final String stage) {
super(app, "SpringNativeAwsFunctionStack",
StackProps.builder().synthesizer(DefaultStackSynthesizer.Builder.create().qualifier("cbcore").build()).build());
super(app, environment);

final List<IManagedPolicy> managedPolicies =
List.of(fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package com.coffeebeans.springnativeawslambda;

import java.util.List;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import com.coffeebeans.springnativeawslambda.model.Secret;
Expand All @@ -29,18 +28,21 @@
import org.springframework.aot.hint.TypeReference;
import org.springframework.lang.Nullable;

import java.util.List;

public class ReflectionRuntimeHints implements RuntimeHintsRegistrar {

@Override
public void registerHints(final RuntimeHints hints, @Nullable final ClassLoader classLoader) {
final List<TypeReference> typeReferences = List.of(
TypeReference.of(DateTime.class),
TypeReference.of(Secret.class),
TypeReference.of(APIGatewayProxyResponseEvent.class),
TypeReference.of(APIGatewayProxyRequestEvent.class),
TypeReference.of(APIGatewayProxyRequestEvent.ProxyRequestContext.class)
);
@Override
public void registerHints(final RuntimeHints hints, @Nullable final ClassLoader classLoader) {
final List<TypeReference> typeReferences = List.of(
TypeReference.of(DateTime.class),
TypeReference.of(Secret.class),
TypeReference.of(APIGatewayProxyResponseEvent.class),
TypeReference.of(APIGatewayProxyRequestEvent.class),
TypeReference.of(APIGatewayProxyRequestEvent.ProxyRequestContext.class),
TypeReference.of(APIGatewayProxyRequestEvent.RequestIdentity.class)
);

hints.reflection().registerTypes(typeReferences, builder -> builder.withMembers(MemberCategory.values()));
}
hints.reflection().registerTypes(typeReferences, builder -> builder.withMembers(MemberCategory.values()));
}
}
2 changes: 1 addition & 1 deletion spring-native-aws-service/src/shell/native/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ set -euo pipefail

cd ${LAMBDA_TASK_ROOT:-.}

./spring-native-aws-function
./spring-native-aws-service

0 comments on commit 25396ad

Please sign in to comment.