From 8629145781ad0bcd6e82bdbe48161154f7520130 Mon Sep 17 00:00:00 2001 From: Ryosuke IWANAGA Date: Wed, 20 Sep 2017 10:11:10 -0700 Subject: [PATCH] Initial commit --- .gitignore | 1 + LICENSE.txt | 201 ++++++++++++++++++ NOTICE.txt | 2 + README.md | 185 ++++++++++++++++ pom.xml | 47 ++++ .../META-INF/maven/archetype-metadata.xml | 29 +++ .../resources/archetype-resources/event.json | 4 + .../resources/archetype-resources/pom.xml | 181 ++++++++++++++++ .../src/main/java/__className__.java | 123 +++++++++++ .../src/main/resources/log4j2.xml | 15 ++ .../archetype-resources/template.yaml | 14 ++ .../projects/package/archetype.properties | 8 + src/test/resources/projects/package/goal.txt | 1 + 13 files changed, 811 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.txt create mode 100644 NOTICE.txt create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 src/main/resources/archetype-resources/event.json create mode 100644 src/main/resources/archetype-resources/pom.xml create mode 100644 src/main/resources/archetype-resources/src/main/java/__className__.java create mode 100644 src/main/resources/archetype-resources/src/main/resources/log4j2.xml create mode 100644 src/main/resources/archetype-resources/template.yaml create mode 100644 src/test/resources/projects/package/archetype.properties create mode 100644 src/test/resources/projects/package/goal.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..8dada3e --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE.txt b/NOTICE.txt new file mode 100644 index 0000000..f3bfb25 --- /dev/null +++ b/NOTICE.txt @@ -0,0 +1,2 @@ +AWS Serverless Java Archtetype +Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/README.md b/README.md new file mode 100644 index 0000000..17df408 --- /dev/null +++ b/README.md @@ -0,0 +1,185 @@ +# AWS Serverless Java Archetype +This is an Apache Maven Archetype to create a simple template for Serverless Java Application. It also creates AWS Serverless Application Model (AWS SAM) template to deploy the application to AWS. + +## Usage + +### Install Archetype on your machine (One time operation) +``` +git clone https://github.com/awslabs/aws-serverless-java-archetype +cd aws-serverless-java-archetype +mvn clean install +``` + +### Create a new application +You can use normal way to create a project from Maven archetype. CLI example is shown below: + +``` +cd /path/to/project_home +mvn archetype:generate \ + -DarchetypeGroupId=com.amazonaws.serverless.archetypes \ + -DarchetypeArtifactId=aws-serverless-java-archetype \ + -DarchetypeVersion=1.0.0 \ + -DarchetypeRepository=local \ # Forcing to use local maven repository + -DinteractiveMode=false \ # For batch mode + + # You can also specify properties below interactively + -DgroupId=YOUR_GROUP_ID \ + -DartifactId=YOUR_ARTIFACT_ID \ + -Dversion=YOUR_VERSION \ + -DclassName=YOUR_CLASSNAME +``` + +### Verify, Build and Deploy your first application +The generated `pom.xml` is configured to use AWS SAM Local to verify, and AWS CLI to build and deploy the application. In order to do them, you need to install tools below: + +- [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/installing.html) +- (Optional) [AWS SAM Local](https://github.com/awslabs/aws-sam-local#installation) + - Also, you need to install Docker as well. Follow the instruction above. + +First, but optionally, you can try to invoke your function locally by the following command: + +``` +mvn -P invoke verify + +[INFO] Scanning for projects... +[INFO] +[INFO] ---------------------------< com.riywo:foo >---------------------------- +[INFO] Building foo 1.0 +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +... +[INFO] +[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ foo --- +[INFO] Building jar: /private/tmp/foo/target/foo-1.0.jar +[INFO] +[INFO] --- maven-shade-plugin:3.1.0:shade (default) @ foo --- +[INFO] Including com.amazonaws:aws-lambda-java-core:jar:1.2.0 in the shaded jar. +[INFO] Minimizing jar com.riywo:foo:jar:1.0 +[INFO] Minimized 20 -> 16 (80%) +[INFO] Replacing /private/tmp/foo/target/lambda.jar with /private/tmp/foo/target/foo-1.0-shaded.jar +[INFO] +[INFO] --- exec-maven-plugin:1.6.0:exec (sam-local-invoke) @ foo --- +2018/04/04 14:20:52 Successfully parsed template.yaml +2018/04/04 14:20:52 Connected to Docker 1.37 +2018/04/04 14:20:52 Fetching lambci/lambda:java8 image for java8 runtime... +java8: Pulling from lambci/lambda +Digest: sha256:14df0a5914d000e15753d739612a506ddb8fa89eaa28dcceff5497d9df2cf7aa +Status: Image is up to date for lambci/lambda:java8 +2018/04/04 14:20:54 Invoking com.riywo.Example (java8) +2018/04/04 14:20:54 Decompressing /tmp/foo/target/lambda.jar +2018/04/04 14:20:54 Mounting /private/var/folders/x5/ldp7c38545v9x5dg_zmkr5kxmpdprx/T/aws-sam-local-1522819254980958624 as /var/task:ro inside runtime container +START RequestId: 31c4cfb1-8d5a-4058-b3de-4c92573f0484 Version: $LATEST +END RequestId: 31c4cfb1-8d5a-4058-b3de-4c92573f0484 +REPORT RequestId: 31c4cfb1-8d5a-4058-b3de-4c92573f0484 Duration: 86.56 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 7 MB + +{"greetings":"Hello Tim Wagner."} + + +[INFO] ------------------------------------------------------------------------ +[INFO] BUILD SUCCESS +[INFO] ------------------------------------------------------------------------ +[INFO] Total time: 10.034 s +[INFO] Finished at: 2018-04-04T14:20:57+09:00 +[INFO] ------------------------------------------------------------------------ +``` + +The maven goal invokes `sam local invoke -e event.json`, so you can see the sample output to greet Tim Wagner. You might want to modify `event.json` for a sample event to your application. + +To deploy this application to AWS, you need an Amazon S3 bucket to upload your package. You can use the following command to create a bucket if you want: + +``` +aws s3 mb s3://YOUR_BUCKET --region YOUR_REGION +``` + +Now, you can deploy your application by just one command! + +``` +mvn deploy \ + -DawsRegion=YOUR_REGION \ + -Ds3Bucket=YOUR_BUCKET \ + -DstackName=YOUR_STACK_NAME + +[INFO] Scanning for projects... +[INFO] +[INFO] ---------------------------< com.riywo:foo >---------------------------- +[INFO] Building foo 1.0 +[INFO] --------------------------------[ jar ]--------------------------------- +[INFO] +... +[INFO] +[INFO] --- exec-maven-plugin:1.6.0:exec (sam-package) @ foo --- +Uploading to aws-serverless-java/com.riywo:foo:1.0/7f77d676053976356674b90a5575f6c3 9552 / 9552.0 (100.00%) +Successfully packaged artifacts and wrote output template to file target/sam.yaml. +Execute the following command to deploy the packaged template +aws cloudformation deploy --template-file /private/tmp/foo/target/sam.yaml --stack-name +[INFO] +[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ foo --- +[INFO] Skipping artifact deployment +[INFO] +[INFO] --- exec-maven-plugin:1.6.0:exec (sam-deploy) @ foo --- + +Waiting for changeset to be created.. +Waiting for stack create/update to complete +Successfully created/updated stack - archetypeTest +[INFO] ------------------------------------------------------------------------ +[INFO] BUILD SUCCESS +[INFO] ------------------------------------------------------------------------ +[INFO] Total time: 39.332 s +[INFO] Finished at: 2018-04-04T14:37:33+09:00 +[INFO] ------------------------------------------------------------------------ +``` + +You can also specify these properties by modifying `pom.xml`. + +The model of your application is AWS SAM. See more details on [AWS SAM documentation](https://docs.aws.amazon.com/lambda/latest/dg/serverless_app.html). + +## Options + +This archetype has some options for creating variants of project. + +### Handler +Lambda Java 8 runtime has some types of handlers: POJO, Simple type and Stream. The default option of this archetype is POJO style, which requires to create request and response classes, but they are baked by the archetype by default. If you want to use other type of handlers, you can use `handlerType` property like below: + +``` +## POJO type (default) +mvn archetype:generate \ + ... + -DhandlerType=pojo + +## Simple type - String +mvn archetype:generate \ + ... + -DhandlerType=simple + +### Stream type +mvn archetype:generate \ + ... + -DhandlerType=stream +``` + +See [documentation](https://docs.aws.amazon.com/lambda/latest/dg/java-programming-model-req-resp.html) for more details about handlers. + +### Logging +Also, Lambda Java 8 runtime supports two types of Logging class: Log4j 2 and LambdaLogger. This archetype creates LambdaLogger implementation by default, but you can use Log4j 2 if you want: + +``` +## LambdaLogger (default) +mvn archetype:generate \ + ... + -Dlogger=lambda + +## Log4j 2 +mvn archetype:generate \ + ... + -Dlogger=log4j2 +``` + +If you use LambdaLogger, you can delete `./src/main/resources/log4j2.xml`. See [documentation](https://docs.aws.amazon.com/lambda/latest/dg/java-logging.html) for more details. + +## Development + +You can run an Integration Test fot this archetype by: + +``` +mvn clean install archetype:integration-test +``` diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c438bdc --- /dev/null +++ b/pom.xml @@ -0,0 +1,47 @@ + + 4.0.0 + + com.amazonaws.serverless.archetypes + aws-serverless-java-archetype + 1.0.0 + AWS Serverless Java Archetype + + + UTF-8 + + + + https://github.com/awslabs/aws-serverless-java-archetype.git + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + + org.apache.maven.archetype + archetype-packaging + 3.0.1 + + + + + + org.apache.maven.plugins + maven-archetype-plugin + 3.0.1 + + true + + + + + + diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000..49c22f1 --- /dev/null +++ b/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,29 @@ + + + + + pojo + + + lambda + + + + + src/main/java + + + src/main/resources + + + + + template.yaml + event.json + + + + diff --git a/src/main/resources/archetype-resources/event.json b/src/main/resources/archetype-resources/event.json new file mode 100644 index 0000000..a2ebdb0 --- /dev/null +++ b/src/main/resources/archetype-resources/event.json @@ -0,0 +1,4 @@ +{ + "firstName": "Tim", + "lastName": "Wagner" +} \ No newline at end of file diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000..98070b4 --- /dev/null +++ b/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,181 @@ + + 4.0.0 + ${groupId} + ${artifactId} + ${version} + + + + + + aws-serverless-java/${project.groupId}:${project.artifactId}:${project.version} + true + UTF-8 + + + +#if (${logger} != 'log4j2') + + + src/main/resources + + log4j2.xml + + + +#end + + + maven-jar-plugin + 3.0.2 + + true + + + + maven-install-plugin + 2.5.2 + + true + + + + maven-deploy-plugin + 2.8.2 + + true + + + + maven-shade-plugin + 3.1.0 + + lambda + false + + + + shade + package + + shade + +#if (${logger} == 'log4j2') + + + + + + +#end + + +#if (${logger} == 'log4j2') + + + com.github.edwgiz + maven-shade-plugin.log4j2-cachefile-transformer + 2.8.1 + + +#end + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + sam-local-invoke + verify + + exec + + + sam + + local + invoke + -e + event.json + + ${skipLocalInvoke} + + + + sam-package + install + + exec + + + aws + + cloudformation + package + --region=${awsRegion} + --template-file=template.yaml + --output-template-file=target/sam.yaml + --s3-bucket=${s3Bucket} + --s3-prefix=${s3Prefix} + + + + + sam-deploy + deploy + + exec + + + aws + + cloudformation + deploy + --region=${awsRegion} + --template-file=target/sam.yaml + --stack-name=${stackName} + --capabilities=CAPABILITY_IAM + + + + + + + + + + + com.amazonaws + aws-lambda-java-core + 1.2.0 + +#if (${logger} == 'log4j2') + + com.amazonaws + aws-lambda-java-log4j2 + 1.0.0 + + + org.apache.logging.log4j + log4j-core + 2.8.2 + + + org.apache.logging.log4j + log4j-api + 2.8.2 + +#end + + + + + invoke + + false + + + + diff --git a/src/main/resources/archetype-resources/src/main/java/__className__.java b/src/main/resources/archetype-resources/src/main/java/__className__.java new file mode 100644 index 0000000..3d23492 --- /dev/null +++ b/src/main/resources/archetype-resources/src/main/java/__className__.java @@ -0,0 +1,123 @@ +/* + * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except + * in compliance with the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package ${package}; + +import com.amazonaws.services.lambda.runtime.Context; +#if (${handlerType} == 'pojo') +import com.amazonaws.services.lambda.runtime.RequestHandler; +#elseif (${handlerType} == 'stream') +import com.amazonaws.services.lambda.runtime.RequestStreamHandler; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; +#end +#if (${logger} == 'log4j2') + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +#elseif (${logger} == 'lambda') + +import com.amazonaws.services.lambda.runtime.LambdaLogger; +#end + +#if (${handlerType} == 'pojo') +public class ${className} implements RequestHandler<${className}.Request, ${className}.Response> { +#elseif (${handlerType} == 'simple') +public class ${className} { +#elseif (${handlerType} == 'stream') +public class ${className} implements RequestStreamHandler { +#end +#if (${logger} == 'log4j2') + static final Logger logger = LogManager.getLogger(${className}.class); + +#end +#if (${handlerType} == 'pojo') + public ${className}.Response handleRequest(${className}.Request request, Context context) { + String greetingString = String.format("Hello %s %s.", request.firstName, request.lastName); +#elseif (${handlerType} == 'simple') + public String handler(String name, Context context) { + String greetingString = String.format("Hello %s.", name); +#elseif (${handlerType} == 'stream') + public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { + String greetingString = "Hello "; + int letter; + while((letter = inputStream.read()) != -1) { + outputStream.write(Character.toUpperCase(letter)); + greetingString += (char) Character.toUpperCase(letter); + } +#end +#if (${logger} == 'lambda') + LambdaLogger logger = context.getLogger(); + logger.log(String.format("Log output: Greeting is '%s'\n", greetingString)); +#elseif (${logger} == 'log4j2') + logger.debug(String.format("Log output: Greeting is '%s'\n", greetingString)); +#end +#if (${handlerType} == 'pojo') + return new ${className}.Response(greetingString); +#elseif (${handlerType} == 'simple') + return greetingString; +#end + } +#if (${handlerType} == 'pojo') + + static class Request { + String firstName; + String lastName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Request(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public Request() { + } + } + + static class Response { + String greetings; + + public String getGreetings() { + return greetings; + } + + public void setGreetings(String greetings) { + this.greetings = greetings; + } + + public Response(String greetings) { + this.greetings = greetings; + } + + public Response() { + } + } +#end +} diff --git a/src/main/resources/archetype-resources/src/main/resources/log4j2.xml b/src/main/resources/archetype-resources/src/main/resources/log4j2.xml new file mode 100644 index 0000000..72b9bf4 --- /dev/null +++ b/src/main/resources/archetype-resources/src/main/resources/log4j2.xml @@ -0,0 +1,15 @@ + + + + + + %d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/archetype-resources/template.yaml b/src/main/resources/archetype-resources/template.yaml new file mode 100644 index 0000000..eec4303 --- /dev/null +++ b/src/main/resources/archetype-resources/template.yaml @@ -0,0 +1,14 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: 'AWS::Serverless-2016-10-31' +Resources: + ${className}Function: + Type: 'AWS::Serverless::Function' + Properties: + Runtime: java8 +#if (${handlerType} == 'simple') + Handler: ${package}.${className}::handler +#else + Handler: ${package}.${className}::handleRequest +#end + Timeout: 60 + CodeUri: ./target/lambda.jar diff --git a/src/test/resources/projects/package/archetype.properties b/src/test/resources/projects/package/archetype.properties new file mode 100644 index 0000000..b0a1e14 --- /dev/null +++ b/src/test/resources/projects/package/archetype.properties @@ -0,0 +1,8 @@ +groupId=com.test +artifactId=test-artifact +version=1.0-SNAPSHOT +package=com.test.pack +className=Example +handlerType=pojo +logger=lambda +skipLocalInvoke=false \ No newline at end of file diff --git a/src/test/resources/projects/package/goal.txt b/src/test/resources/projects/package/goal.txt new file mode 100644 index 0000000..0b59873 --- /dev/null +++ b/src/test/resources/projects/package/goal.txt @@ -0,0 +1 @@ +verify