Skip to content

Commit

Permalink
use sandpiper infra
Browse files Browse the repository at this point in the history
Signed-off-by: matto <muhamadto@gmail.com>
  • Loading branch information
muhamadto committed Mar 25, 2024
1 parent 0b97b1f commit b2e3126
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
47 changes: 29 additions & 18 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,7 +446,10 @@ 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

POST

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

GET

```shell
curl --location --request POST 'http://localhost:8080' \
--header 'Content-Type: application/json' \
--data-raw '{
"httpMethod": "GET",
"pathParameters": {
"proxy": "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
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 b2e3126

Please sign in to comment.