diff --git a/.gitignore b/.gitignore index 27ae4de..596525e 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,5 @@ hs_err_pid* # vscode project setting files **/.project -**/.settings/* \ No newline at end of file +**/.settings/* +/.idea/ diff --git a/graal-native-on-lambda/.gitignore b/graal-native-on-lambda/.gitignore index 25c557d..db7fa48 100644 --- a/graal-native-on-lambda/.gitignore +++ b/graal-native-on-lambda/.gitignore @@ -4,3 +4,4 @@ /out *.zip aws-graal +.classpath diff --git a/java-on-lambda-dynamodb/pom.xml b/java-on-lambda-dynamodb/pom.xml index 0a90340..b89dbdf 100644 --- a/java-on-lambda-dynamodb/pom.xml +++ b/java-on-lambda-dynamodb/pom.xml @@ -42,7 +42,7 @@ com.fasterxml.jackson.core jackson-databind - 2.9.9 + 2.13.4.1 com.fasterxml.jackson.core diff --git a/java-on-lambda-redis/pom.xml b/java-on-lambda-redis/pom.xml index ff6f55e..218ac9e 100644 --- a/java-on-lambda-redis/pom.xml +++ b/java-on-lambda-redis/pom.xml @@ -27,7 +27,7 @@ com.fasterxml.jackson.core jackson-databind - 2.9.9 + 2.12.7.1 com.fasterxml.jackson.core diff --git a/java-on-lambda/pom.xml b/java-on-lambda/pom.xml index 4f2a683..8a1f8fb 100644 --- a/java-on-lambda/pom.xml +++ b/java-on-lambda/pom.xml @@ -27,7 +27,7 @@ com.fasterxml.jackson.core jackson-databind - 2.9.9 + 2.13.4.1 com.fasterxml.jackson.core diff --git a/java-on-lambda/serverless.yml b/java-on-lambda/serverless.yml index 8a88ac0..b2cfac3 100644 --- a/java-on-lambda/serverless.yml +++ b/java-on-lambda/serverless.yml @@ -5,7 +5,7 @@ provider: runtime: java8 endpointType: REGIONAL stage: dev - region: ap-northeast-1 + region: us-east-1 tracing: apiGateway: true lambda: true diff --git a/nodejs-on-lambda-redis/package-lock.json b/nodejs-on-lambda-redis/package-lock.json index fad863e..8bf19de 100644 --- a/nodejs-on-lambda-redis/package-lock.json +++ b/nodejs-on-lambda-redis/package-lock.json @@ -4,30 +4,39 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "double-ended-queue": { - "version": "2.1.0-0", - "resolved": "https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz", - "integrity": "sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw=" + "denque": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.0.tgz", + "integrity": "sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ==" }, "redis": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/redis/-/redis-2.8.0.tgz", - "integrity": "sha512-M1OkonEQwtRmZv4tEWF2VgpG0JWJ8Fv1PhlgT5+B+uNq2cA3Rt1Yt/ryoR+vQNOQcIEgdCdfH0jr3bDpihAw1A==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/redis/-/redis-3.1.1.tgz", + "integrity": "sha512-QhkKhOuzhogR1NDJfBD34TQJz2ZJwDhhIC6ZmvpftlmfYShHHQXjjNspAJ+Z2HH5NwSBVYBVganbiZ8bgFMHjg==", "requires": { - "double-ended-queue": "^2.1.0-0", - "redis-commands": "^1.2.0", - "redis-parser": "^2.6.0" + "denque": "^1.5.0", + "redis-commands": "^1.7.0", + "redis-errors": "^1.2.0", + "redis-parser": "^3.0.0" } }, "redis-commands": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.5.0.tgz", - "integrity": "sha512-6KxamqpZ468MeQC3bkWmCB1fp56XL64D4Kf0zJSwDZbVLLm7KFkoIcHrgRvQ+sk8dnhySs7+yBg94yIkAK7aJg==" + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz", + "integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ==" + }, + "redis-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz", + "integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60=" }, "redis-parser": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-2.6.0.tgz", - "integrity": "sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs=" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", + "integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=", + "requires": { + "redis-errors": "^1.0.0" + } } } } diff --git a/nodejs-on-lambda-redis/package.json b/nodejs-on-lambda-redis/package.json index ef0e95e..fb8bb66 100644 --- a/nodejs-on-lambda-redis/package.json +++ b/nodejs-on-lambda-redis/package.json @@ -10,7 +10,7 @@ "author": "", "license": "ISC", "dependencies": { - "redis": "^2.8.0" + "redis": "^3.1.1" }, "devDependencies": {} } diff --git a/quarkus-on-lambda-redis/serverless.yml b/quarkus-on-lambda-redis/serverless.yml index 0fb14cd..0ddb393 100644 --- a/quarkus-on-lambda-redis/serverless.yml +++ b/quarkus-on-lambda-redis/serverless.yml @@ -4,7 +4,7 @@ provider: name: aws runtime: provided stage: dev - region: ap-northeast-1 + region: us-east-1 endpointType: REGIONAL tracing: apiGateway: true @@ -20,12 +20,12 @@ functions: - http: ANY / - http: 'ANY {proxy+}' environment: - REDIS_HOST: demo.j5hprq.0001.apne1.cache.amazonaws.com + REDIS_HOST: demo.uhm99s.0001.use1.cache.amazonaws.com vpc: securityGroupIds: - - sg-61dbd018 + - sg-e9d737a0 subnetIds: - - subnet-1716355e - - subnet-2acaf602 - - subnet-a0a834fb + - subnet-584fab3f + - subnet-c169bf8b + - subnet-867b76db diff --git a/quarkus-sns-firehose-example/manage.sh b/quarkus-sns-firehose-example/manage.sh new file mode 100644 index 0000000..80295a4 --- /dev/null +++ b/quarkus-sns-firehose-example/manage.sh @@ -0,0 +1,50 @@ +function cmd_create() { + echo Creating function + aws lambda create-function \ + --function-name ${FUNCTION_NAME} \ + --zip-file ${ZIP_FILE} \ + --handler ${HANDLER} \ + --runtime ${RUNTIME} \ + --role ${LAMBDA_ROLE_ARN} \ + ${LAMBDA_META} +} + +function cmd_delete() { + echo Deleting function + aws lambda delete-function --function-name ${FUNCTION_NAME} +} + +function cmd_invoke() { + echo Invoking function + aws lambda invoke response.txt \ + --function-name ${FUNCTION_NAME} \ + --payload file://payload.json +} + +function cmd_update() { + echo Updating function + aws lambda update-function-code \ + --function-name ${FUNCTION_NAME} \ + --zip-file ${ZIP_FILE} +} + +FUNCTION_NAME=QuarkusSnsFirehoseExampleFunction +HANDLER=io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest +RUNTIME=java8 +ZIP_FILE=fileb://target/quarkus-sns-firehose-example-1.0-SNAPSHOT-runner.jar + +if [ "$1" == "native" ] +then + RUNTIME=provided + ZIP_FILE=fileb://target/function.zip + FUNCTION_NAME=QuarkusSnsFirehoseExampleNativeFunction + LAMBDA_META="--environment Variables={DISABLE_SIGNAL_HANDLERS=true}" + shift +fi + +while [ "$1" ] +do + eval cmd_${1} + shift +done + diff --git a/quarkus-sns-firehose-example/payload.json b/quarkus-sns-firehose-example/payload.json new file mode 100644 index 0000000..b81dea5 --- /dev/null +++ b/quarkus-sns-firehose-example/payload.json @@ -0,0 +1,4 @@ +{ + "name": "Bill", + "greeting": "hello" +} \ No newline at end of file diff --git a/quarkus-sns-firehose-example/pom.xml b/quarkus-sns-firehose-example/pom.xml new file mode 100644 index 0000000..a76b2c1 --- /dev/null +++ b/quarkus-sns-firehose-example/pom.xml @@ -0,0 +1,157 @@ + + + 4.0.0 + com.amazonaws.serverless.sample + quarkus-sns-firehose-example + 1.0-SNAPSHOT + + UTF-8 + 2.22.0 + true + 999-SNAPSHOT + + 3.8.1 + 1.8 + UTF-8 + 1.8 + 2.10.78 + + + + + io.quarkus + quarkus-bom + ${quarkus.version} + pom + import + + + software.amazon.awssdk + bom + ${awssdk.version} + pom + import + + + + + + io.quarkus + quarkus-amazon-lambda + + + software.amazon.awssdk + firehose + + + software.amazon.awssdk + http-client-spi + + + software.amazon.awssdk + netty-nio-client + + + software.amazon.awssdk + apache-client + + + + + software.amazon.awssdk + url-connection-client + + + + + + io.quarkus + quarkus-maven-plugin + ${quarkus.version} + + true + + + + + build + + + + + + maven-compiler-plugin + 3.8.1 + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + + + + + + + + native + + + native + + + + + + io.quarkus + quarkus-maven-plugin + ${quarkus.version} + + + + native-image + + + true + true + true + true + + --allow-incomplete-classpath + --initialize-at-run-time=io.netty.util.internal.logging.Log4JLogger + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.1.0 + + + zip-assembly + package + + single + + + function + + src/assembly/zip.xml + + false + false + + + + + + + + + diff --git a/quarkus-sns-firehose-example/sam.jvm.yaml b/quarkus-sns-firehose-example/sam.jvm.yaml new file mode 100644 index 0000000..6b08199 --- /dev/null +++ b/quarkus-sns-firehose-example/sam.jvm.yaml @@ -0,0 +1,19 @@ + AWSTemplateFormatVersion: '2010-09-09' + Transform: AWS::Serverless-2016-10-31 + Description: AWS Serverless Quarkus HTTP - com.amazonaws.serverless.sample::quarkus-sns-firehose-example + Globals: + Api: + EndpointConfiguration: REGIONAL + BinaryMediaTypes: + - "*/*" + + Resources: + QuarkusSnsFirehoseExampleFunction: + Type: AWS::Serverless::Function + Properties: + Handler: io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest + Runtime: java8 + CodeUri: target/quarkus-sns-firehose-example-1.0-SNAPSHOT-runner.jar + MemorySize: 128 + Timeout: 15 + Policies: AWSLambdaBasicExecutionRole \ No newline at end of file diff --git a/quarkus-sns-firehose-example/sam.native.yaml b/quarkus-sns-firehose-example/sam.native.yaml new file mode 100644 index 0000000..bbbc9a1 --- /dev/null +++ b/quarkus-sns-firehose-example/sam.native.yaml @@ -0,0 +1,21 @@ + AWSTemplateFormatVersion: '2010-09-09' + Transform: AWS::Serverless-2016-10-31 + Description: AWS Serverless Quarkus HTTP - com.amazonaws.serverless.sample::quarkus-sns-firehose-example + Globals: + Api: + BinaryMediaTypes: + - "*/*" + + Resources: + QuarkusSnsFirehoseExampleNativeFunction: + Type: AWS::Serverless::Function + Properties: + Handler: not.used.in.provided.runtimei + Runtime: provided + CodeUri: target/function.zip + MemorySize: 128 + Policies: AWSLambdaBasicExecutionRole + Timeout: 15 + Environment: + Variables: + DISABLE_SIGNAL_HANDLERS: true diff --git a/quarkus-sns-firehose-example/src/assembly/zip.xml b/quarkus-sns-firehose-example/src/assembly/zip.xml new file mode 100644 index 0000000..c22553c --- /dev/null +++ b/quarkus-sns-firehose-example/src/assembly/zip.xml @@ -0,0 +1,35 @@ + + lambda-package + + zip + + false + + + ${project.build.directory}${file.separator}${artifactId}-${version}-runner + / + application + 755 + + + ${project.build.directory}${file.separator}classes${file.separator}bootstrap + / + bootstrap + 755 + + + ${project.build.directory}${file.separator}classes${file.separator}cacerts + / + cacerts + 644 + + + ${project.build.directory}${file.separator}classes${file.separator}libsunec.so + / + libsunec.so + 644 + + + diff --git a/quarkus-sns-firehose-example/src/main/java/com/amazonaws/serverless/sample/quarkus/sns2firehose/ProcessingService.java b/quarkus-sns-firehose-example/src/main/java/com/amazonaws/serverless/sample/quarkus/sns2firehose/ProcessingService.java new file mode 100644 index 0000000..6a6bd1b --- /dev/null +++ b/quarkus-sns-firehose-example/src/main/java/com/amazonaws/serverless/sample/quarkus/sns2firehose/ProcessingService.java @@ -0,0 +1,33 @@ +package com.amazonaws.serverless.sample.quarkus.sns2firehose; + +import com.amazonaws.services.lambda.runtime.events.SNSEvent; +import com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord; +import com.amazonaws.services.lambda.runtime.LambdaLogger; +import software.amazon.awssdk.core.SdkBytes; +import software.amazon.awssdk.services.firehose.FirehoseClient; +import software.amazon.awssdk.services.firehose.model.PutRecordRequest; +import software.amazon.awssdk.services.firehose.model.Record; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class ProcessingService { + + public void process(SNSEvent snsEvent, LambdaLogger logger, FirehoseClient firehoseClient) { + logger.log("before send to firehose"); + + // get the sns record + SNSRecord snsRecord = snsEvent.getRecords().get(0); + + // prepare the pur record request + PutRecordRequest putRecordRequest = PutRecordRequest.builder() + .deliveryStreamName("sns-message-stream") + .record(Record.builder().data(SdkBytes.fromUtf8String(snsRecord.toString() + "\n")).build()) + .build(); + + // Put record into the DeliveryStream + firehoseClient.putRecord(putRecordRequest); + + logger.log("after send to firehose"); + } +} diff --git a/quarkus-sns-firehose-example/src/main/java/com/amazonaws/serverless/sample/quarkus/sns2firehose/TestLambda.java b/quarkus-sns-firehose-example/src/main/java/com/amazonaws/serverless/sample/quarkus/sns2firehose/TestLambda.java new file mode 100644 index 0000000..d7be0e9 --- /dev/null +++ b/quarkus-sns-firehose-example/src/main/java/com/amazonaws/serverless/sample/quarkus/sns2firehose/TestLambda.java @@ -0,0 +1,37 @@ +package com.amazonaws.serverless.sample.quarkus.sns2firehose; + +import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.LambdaLogger; +import com.amazonaws.services.lambda.runtime.RequestHandler; +import com.amazonaws.services.lambda.runtime.events.SNSEvent; +import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider; +import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.firehose.FirehoseClient; + +import javax.inject.Inject; + +public class TestLambda implements RequestHandler { + + @Inject + ProcessingService service; + + FirehoseClient firehoseClient = FirehoseClient.builder() + .region(Region.US_WEST_2) + .credentialsProvider(EnvironmentVariableCredentialsProvider.create()) + .httpClientBuilder(UrlConnectionHttpClient.builder()) + .build(); + + @Override + public Void handleRequest(SNSEvent snsEvent, Context context) { + LambdaLogger logger = context.getLogger(); + + logger.log("before service"); + + service.process(snsEvent, logger, firehoseClient); + + logger.log("after service"); + + return null; + } +} diff --git a/quarkus-sns-firehose-example/src/main/resources/application.properties b/quarkus-sns-firehose-example/src/main/resources/application.properties new file mode 100644 index 0000000..ed9240e --- /dev/null +++ b/quarkus-sns-firehose-example/src/main/resources/application.properties @@ -0,0 +1,3 @@ +quarkus.native.container-build=true +quarkus.native.container-runtime=docker +quarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-native-image:19.3.1-java8 diff --git a/quarkus-sns-firehose-example/src/main/resources/bootstrap b/quarkus-sns-firehose-example/src/main/resources/bootstrap new file mode 100755 index 0000000..fb9a30e --- /dev/null +++ b/quarkus-sns-firehose-example/src/main/resources/bootstrap @@ -0,0 +1,3 @@ +#!/bin/bash + +./application -Djavax.net.ssl.trustStore=./cacerts -Djava.library.path=. \ No newline at end of file diff --git a/quarkus-sns-firehose-example/src/main/resources/cacerts b/quarkus-sns-firehose-example/src/main/resources/cacerts new file mode 100644 index 0000000..02181be Binary files /dev/null and b/quarkus-sns-firehose-example/src/main/resources/cacerts differ diff --git a/quarkus-sns-firehose-example/src/main/resources/libsunec.so b/quarkus-sns-firehose-example/src/main/resources/libsunec.so new file mode 100755 index 0000000..a3be21f Binary files /dev/null and b/quarkus-sns-firehose-example/src/main/resources/libsunec.so differ diff --git a/quarkus-spring-on-lambda/pet-store/README.md b/quarkus-spring-on-lambda/pet-store/README.md new file mode 100644 index 0000000..3ff1371 --- /dev/null +++ b/quarkus-spring-on-lambda/pet-store/README.md @@ -0,0 +1,68 @@ +# Quarkus Native Pet store example + +The [Quarkus framework](https://quarkus.io/) is compatible with Spring's annotations and makes it easy to use [GraalVM](https://www.graalvm.org/) to build application images into native binaries. Further, Micronaut includes builtin support for AWS Lambda. + +This demo application shows how to use Quarkus to compile our standard pet store example, using Spring annotations, into a native binary with GraalVM and execute it in AWS Lambda. To run this demo, you will need to have [Maven](https://maven.apache.org/) installed as well as [Docker](https://www.docker.com/) to build GraalVM native image. + +With all the pre-requisites installed including: + +* JDK 8 or above +* Maven 3.5.x + +You should be able to build a native image of the application by running mvn from the repository's root. + +```bash +$ mvn clean install -Pnative +``` + +The output of the build is a deployable zip called `function.zip` in the `target` folder. + +To run the lambda locally, you can utilize the SAM cli. This should start up the listeners in the `PetsController`, and you can test locally with your preferred http client. + +```bash +sam local start-api -t sam.native.yaml +``` + +For example, to test the GET /pets endpoint via curl: +```bash +curl localhost:3000/pets +``` + +You should see JSON output of pets. + +To deploy the application to AWS Lambda you can use the pre-configured `sam-native.yaml` file included in the repo. Using the AWS or SAM CLI, run the following commands: + +```bash +sam deploy -g -t sam.native.yaml +``` + +You should see the stack deployed successfully: + +```bash +Stack quarkus-sample-pet-store outputs: +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +OutputKey-Description OutputValue +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +PetStoreNativeApi - URL for application https://xxxxxxxxxx.execute-api.xx-xxxx-1.amazonaws.com/Prod/ +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +Successfully created/updated stack - quarkus-sample-pet-store in xx-xxxx-1 + +``` + +Make a test request to the API endpoint using curl or your preferred http client. + +For example, to check the GET /pets endpoint via curl: +```bash +curl https://xxxxxxxxxx.execute-api.xx-xxxx-1.amazonaws.com/Prod/pets +``` + +Finally, there’s an environment variable that must be set for native GraalVM deployments. If you look at sam.native.yaml you’ll see this: + +```bash + Environment: + Variables: + DISABLE_SIGNAL_HANDLERS: true +``` + +This environment variable resolves some incompatibilites between GraalVM and the Amazon Lambda Custom Runtime environment. \ No newline at end of file diff --git a/quarkus-spring-on-lambda/pet-store/pom.xml b/quarkus-spring-on-lambda/pet-store/pom.xml new file mode 100644 index 0000000..0147be8 --- /dev/null +++ b/quarkus-spring-on-lambda/pet-store/pom.xml @@ -0,0 +1,141 @@ + + + 4.0.0 + com.amazonaws.serverless.sample + serverless-quarkus-example + 1.0-SNAPSHOT + + 3.8.1 + true + 1.8 + 1.8 + UTF-8 + UTF-8 + 1.0.1.Final + quarkus-universe-bom + io.quarkus + 1.0.1.Final + 2.22.1 + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-amazon-lambda-http + + + io.quarkus + quarkus-spring-web + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + io.quarkus + quarkus-maven-plugin + ${quarkus-plugin.version} + + + + build + + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + + + + + + + + native + + + native + + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.1.0 + + + zip-assembly + package + + single + + + function + + src/assembly/zip.xml + + false + false + + + + + + + + native + + + + diff --git a/quarkus-spring-on-lambda/pet-store/sam.native.yaml b/quarkus-spring-on-lambda/pet-store/sam.native.yaml new file mode 100644 index 0000000..54ca55d --- /dev/null +++ b/quarkus-spring-on-lambda/pet-store/sam.native.yaml @@ -0,0 +1,36 @@ + AWSTemplateFormatVersion: '2010-09-09' + Transform: AWS::Serverless-2016-10-31 + Description: AWS Serverless Quarkus HTTP - com.amazon.quarkus.demo::pet-store + Globals: + Api: + EndpointConfiguration: REGIONAL + BinaryMediaTypes: + - "*/*" + + Resources: + PetStoreNativeFunction: + Type: AWS::Serverless::Function + Properties: + Handler: not.used.in.provided.runtime + Runtime: provided + CodeUri: target/function.zip + MemorySize: 128 + Policies: AWSLambdaBasicExecutionRole + Tracing: Active + Timeout: 15 + Environment: + Variables: + DISABLE_SIGNAL_HANDLERS: true + Events: + GetResource: + Type: Api + Properties: + Path: /{proxy+} + Method: any + + Outputs: + PetStoreNativeApi: + Description: URL for application + Value: !Sub 'https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/' + Export: + Name: PetStoreNativeApi diff --git a/quarkus-spring-on-lambda/pet-store/src/assembly/zip.xml b/quarkus-spring-on-lambda/pet-store/src/assembly/zip.xml new file mode 100644 index 0000000..ce2cb64 --- /dev/null +++ b/quarkus-spring-on-lambda/pet-store/src/assembly/zip.xml @@ -0,0 +1,17 @@ + + lambda-package + + zip + + false + + + ${project.build.directory}${file.separator}${artifactId}-${version}-runner + / + bootstrap + 755 + + + diff --git a/quarkus-spring-on-lambda/pet-store/src/main/java/com/amazonaws/serverless/sample/quarkus/PetsController.java b/quarkus-spring-on-lambda/pet-store/src/main/java/com/amazonaws/serverless/sample/quarkus/PetsController.java new file mode 100644 index 0000000..5718878 --- /dev/null +++ b/quarkus-spring-on-lambda/pet-store/src/main/java/com/amazonaws/serverless/sample/quarkus/PetsController.java @@ -0,0 +1,63 @@ +package com.amazonaws.serverless.sample.quarkus; + +import com.amazonaws.serverless.sample.quarkus.model.Pet; +import com.amazonaws.serverless.sample.quarkus.model.PetData; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Optional; +import java.util.UUID; + +@RestController +public class PetsController { + + private PetData petData; + + @Autowired + public PetsController(PetData data) { + petData = data; + } + + @RequestMapping(path = "/pets", method = RequestMethod.POST) + public Pet createPet(@RequestBody Pet newPet) { + if (newPet.getName() == null || newPet.getBreed() == null) { + return null; + } + + Pet dbPet = newPet; + dbPet.setId(UUID.randomUUID().toString()); + return dbPet; + } + + @RequestMapping(path = "/pets", method = RequestMethod.GET) + public Pet[] listPets(@RequestParam("limit") Optional limit) { + int queryLimit = 10; + if (limit.isPresent()) { + queryLimit = limit.get(); + } + + Pet[] outputPets = new Pet[queryLimit]; + + for (int i = 0; i < queryLimit; i++) { + Pet newPet = new Pet(); + newPet.setId(UUID.randomUUID().toString()); + newPet.setName(petData.getRandomName()); + newPet.setBreed(petData.getRandomBreed()); + newPet.setDateOfBirth(petData.getRandomDoB()); + outputPets[i] = newPet; + } + + return outputPets; + } + + @RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET) + public Pet getPet(@RequestParam("petId") String petId) { + Pet newPet = new Pet(); + newPet.setId(UUID.randomUUID().toString()); + newPet.setBreed(petData.getRandomBreed()); + newPet.setDateOfBirth(petData.getRandomDoB()); + newPet.setName(petData.getRandomName()); + return newPet; + } + +} diff --git a/quarkus-spring-on-lambda/pet-store/src/main/java/com/amazonaws/serverless/sample/quarkus/model/Pet.java b/quarkus-spring-on-lambda/pet-store/src/main/java/com/amazonaws/serverless/sample/quarkus/model/Pet.java new file mode 100644 index 0000000..4752133 --- /dev/null +++ b/quarkus-spring-on-lambda/pet-store/src/main/java/com/amazonaws/serverless/sample/quarkus/model/Pet.java @@ -0,0 +1,50 @@ +package com.amazonaws.serverless.sample.quarkus.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +import java.util.Date; + +@RegisterForReflection +public class Pet { + private String id; + private String breed; + private String name; + private Date dateOfBirth; + + @JsonProperty("petId") + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getBreed() { + return breed; + } + + public void setBreed(String breed) { + this.breed = breed; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @JsonFormat(pattern = "YYYY-mm-dd") + public Date getDateOfBirth() { + return dateOfBirth; + } + + public void setDateOfBirth(Date dateOfBirth) { + this.dateOfBirth = dateOfBirth; + } + +} diff --git a/quarkus-spring-on-lambda/pet-store/src/main/java/com/amazonaws/serverless/sample/quarkus/model/PetData.java b/quarkus-spring-on-lambda/pet-store/src/main/java/com/amazonaws/serverless/sample/quarkus/model/PetData.java new file mode 100644 index 0000000..90b837d --- /dev/null +++ b/quarkus-spring-on-lambda/pet-store/src/main/java/com/amazonaws/serverless/sample/quarkus/model/PetData.java @@ -0,0 +1,102 @@ +package com.amazonaws.serverless.sample.quarkus.model; + +import org.springframework.stereotype.Component; + +import java.util.*; +import java.util.concurrent.ThreadLocalRandom; + +@Component +public class PetData { + private static List breeds = new ArrayList<>(); + static { + breeds.add("Afghan Hound"); + breeds.add("Beagle"); + breeds.add("Bernese Mountain Dog"); + breeds.add("Bloodhound"); + breeds.add("Dalmatian"); + breeds.add("Jack Russell Terrier"); + breeds.add("Norwegian Elkhound"); + } + + private static List names = new ArrayList<>(); + static { + names.add("Bailey"); + names.add("Bella"); + names.add("Max"); + names.add("Lucy"); + names.add("Charlie"); + names.add("Molly"); + names.add("Buddy"); + names.add("Daisy"); + names.add("Rocky"); + names.add("Maggie"); + names.add("Jake"); + names.add("Sophie"); + names.add("Jack"); + names.add("Sadie"); + names.add("Toby"); + names.add("Chloe"); + names.add("Cody"); + names.add("Bailey"); + names.add("Buster"); + names.add("Lola"); + names.add("Duke"); + names.add("Zoe"); + names.add("Cooper"); + names.add("Abby"); + names.add("Riley"); + names.add("Ginger"); + names.add("Harley"); + names.add("Roxy"); + names.add("Bear"); + names.add("Gracie"); + names.add("Tucker"); + names.add("Coco"); + names.add("Murphy"); + names.add("Sasha"); + names.add("Lucky"); + names.add("Lily"); + names.add("Oliver"); + names.add("Angel"); + names.add("Sam"); + names.add("Princess"); + names.add("Oscar"); + names.add("Emma"); + names.add("Teddy"); + names.add("Annie"); + names.add("Winston"); + names.add("Rosie"); + } + + public List getBreeds() { + return breeds; + } + + public List getNames() { + return names; + } + + public String getRandomBreed() { + return breeds.get(ThreadLocalRandom.current().nextInt(0, breeds.size() - 1)); + } + + public String getRandomName() { + return names.get(ThreadLocalRandom.current().nextInt(0, names.size() - 1)); + } + + public Date getRandomDoB() { + GregorianCalendar gc = new GregorianCalendar(); + + int year = ThreadLocalRandom.current().nextInt( + Calendar.getInstance().get(Calendar.YEAR) - 15, + Calendar.getInstance().get(Calendar.YEAR) + ); + + gc.set(Calendar.YEAR, year); + + int dayOfYear = ThreadLocalRandom.current().nextInt(1, gc.getActualMaximum(Calendar.DAY_OF_YEAR)); + + gc.set(Calendar.DAY_OF_YEAR, dayOfYear); + return gc.getTime(); + } +} diff --git a/quarkus-spring-on-lambda/pet-store/src/main/resources/application.properties b/quarkus-spring-on-lambda/pet-store/src/main/resources/application.properties new file mode 100644 index 0000000..ee9b09c --- /dev/null +++ b/quarkus-spring-on-lambda/pet-store/src/main/resources/application.properties @@ -0,0 +1,4 @@ +quarkus.native.container-build=true +quarkus.native.container-runtime=docker +quarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-native-image:19.2.1 +quarkus.log.level=INFO \ No newline at end of file diff --git a/vertx-on-lambda/pom.xml b/vertx-on-lambda/pom.xml index bb36673..2c2fa1a 100644 --- a/vertx-on-lambda/pom.xml +++ b/vertx-on-lambda/pom.xml @@ -44,7 +44,7 @@ junit junit - 4.12 + 4.13.1 test