diff --git a/README.md b/README.md index e9d60bb..a2f9fd4 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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 @@ -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 '{ @@ -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. diff --git a/cdk.json b/cdk.json index 323e56b..04ac302 100644 --- a/cdk.json +++ b/cdk.json @@ -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" } diff --git a/docker-compose.yml b/docker-compose.yml index 9e14073..696ff14 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/spring-native-aws-service-infra/src/main/java/com/coffeebeans/springnativeawslambda/infra/SpringNativeAwsFunctionStack.java b/spring-native-aws-service-infra/src/main/java/com/coffeebeans/springnativeawslambda/infra/SpringNativeAwsFunctionStack.java index 5ac3173..ace88d6 100644 --- a/spring-native-aws-service-infra/src/main/java/com/coffeebeans/springnativeawslambda/infra/SpringNativeAwsFunctionStack.java +++ b/spring-native-aws-service-infra/src/main/java/com/coffeebeans/springnativeawslambda/infra/SpringNativeAwsFunctionStack.java @@ -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; @@ -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; @@ -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 managedPolicies = List.of(fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole")); diff --git a/spring-native-aws-service/src/shell/native/bootstrap b/spring-native-aws-service/src/shell/native/bootstrap index b3118d4..ff8d3b6 100755 --- a/spring-native-aws-service/src/shell/native/bootstrap +++ b/spring-native-aws-service/src/shell/native/bootstrap @@ -21,4 +21,4 @@ set -euo pipefail cd ${LAMBDA_TASK_ROOT:-.} -./spring-native-aws-function \ No newline at end of file +./spring-native-aws-service \ No newline at end of file