-
Notifications
You must be signed in to change notification settings - Fork 914
Add support for maven lambda archetype #1678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Maven Archetypes for AWS SDK for Java 2.x | ||
|
||
## Description | ||
This module contains maven archetypes for AWS Java SDK 2.x. | ||
|
||
## Archetypes | ||
|
||
- [archetype-lambda](archetype-lambda/README.md) - a lambda function template using AWS Java SDK 2.x | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Maven Archetype for lambda function using AWS SDK for Java 2.x | ||
|
||
## Description | ||
This is an Apache Maven Archetype to create a lambda function template using [AWS Java SDK 2.x][aws-java-sdk-v2]. The generated template | ||
has the optimized configurations and follows the best practices to reduce start up time. | ||
|
||
## Usage | ||
|
||
You can use `mvn archetype:generate` to generate a project using this archetype. See [maven archetype usage guidance][maven-archetype-usage] for more information. | ||
|
||
- Interactive mode | ||
|
||
``` | ||
mvn archetype:generate \ | ||
-DarchetypeGroupId=software.amazon.awssdk \ | ||
-DarchetypeArtifactId=archetype-lambda \ | ||
-DarchetypeVersion=2.x\ | ||
``` | ||
|
||
- Batch mode | ||
|
||
``` | ||
mvn archetype:generate \ | ||
-DarchetypeGroupId=software.amazon.awssdk \ | ||
-DarchetypeArtifactId=archetype-lambda \ | ||
-DarchetypeVersion=2.x\ | ||
-DgroupId=com.test \ | ||
-DartifactId=sample-project \ | ||
-Dservice=s3 \ | ||
-Dregion=us-west-2 \ | ||
-DinteractiveMode=false \ | ||
``` | ||
|
||
### Parameters | ||
Parameter Name | Default Value | Description | ||
---|---|--- | ||
`service` (required) | n/a | Specifies the service client to be used in the lambda function, eg: s3, dynamodb. You can find available services [here][java-sdk-v2-services]. | ||
`region` (required) | n/a | Specifies the region to be set for the SDK client in the application | ||
`groupId`(required) | n/a | Specifies the group ID of the project | ||
`artifactId`(required) | n/a | Specifies the artifact ID of the project | ||
`httpClient` | url-connection-client | Specifies the http client to be used by the SDK client. Available options are `url-connection-client` (sync), `apache-client` (sync), `netty-nio-client` (async). See [http clients][sdk-http-clients] | ||
`handlerClassName` | `"App"`| Specifies the class name of the handler, which will be used as the lambda function name. It should be camel case. | ||
`javaSdkVersion` | Same version as the archetype version | Specifies the version of the AWS Java SDK 2.x to be used | ||
`version` | 1.0-SNAPSHOT | Specifies the version of the project | ||
`package` | ${groupId} | Specifies the package name for the classes | ||
|
||
### Deployment | ||
|
||
To deploy the lambda function, you can use [SAM CLI][sam-cli]. The generated project contains a default [SAM template][sam-template] file `template.yaml` where you can | ||
configure different properties of your lambda function such as memory size and timeout. | ||
|
||
``` | ||
sam deploy --guided | ||
``` | ||
|
||
Please refer to [deploying lambda apps][deploying-lambda-apps] for more info. | ||
|
||
[aws-java-sdk-v2]: https://github.com/aws/aws-sdk-java-v2 | ||
[java-sdk-v2-services]: https://github.com/aws/aws-sdk-java-v2/tree/master/services | ||
[sdk-http-clients]: https://github.com/aws/aws-sdk-java-v2/tree/master/http-clients | ||
[deploying-lambda-apps]: https://docs.aws.amazon.com/lambda/latest/dg/deploying-lambda-apps.html | ||
[sam-cli]:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started.html | ||
[maven-archetype-usage]: https://maven.apache.org/archetype/maven-archetype-plugin/usage.html | ||
[sam-template]: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2010-2020 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>archetypes</artifactId> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<version>2.11.4-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>archetype-lambda</artifactId> | ||
<packaging>maven-archetype</packaging> | ||
<name>AWS Java SDK :: Archetype Lambda</name> | ||
<description> | ||
The AWS SDK for Java - Maven archetype for Java lambda function using AWS Java SDK 2.x | ||
</description> | ||
|
||
<properties> | ||
<maven.archetype.version>3.1.2</maven.archetype.version> | ||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- Depends on the artifacts of all services to generate serviceMapping.vm --> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>aws-sdk-java</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<!-- Filtering the resource properties to get ${project.version} from archetype metadata. | ||
See https://stackoverflow.com/a/22300149 --> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
<includes> | ||
<include>META-INF/maven/archetype-metadata.xml</include> | ||
</includes> | ||
</resource> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>false</filtering> | ||
<excludes> | ||
<exclude>META-INF/maven/archetype-metadata.xml</exclude> | ||
</excludes> | ||
</resource> | ||
</resources> | ||
<extensions> | ||
<extension> | ||
<groupId>org.apache.maven.archetype</groupId> | ||
<artifactId>archetype-packaging</artifactId> | ||
<version>${maven.archetype.version}</version> | ||
</extension> | ||
</extensions> | ||
|
||
<plugins> | ||
<plugin> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<version>${exec-maven-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>map-service-to-client-prefix</id> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>exec</goal> | ||
</goals> | ||
<configuration> | ||
<executable>${basedir}/src/main/resources/map-service-to-client-prefix</executable> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-archetype-plugin</artifactId> | ||
<version>${maven.archetype.version}</version> | ||
<configuration> | ||
<noLog>true</noLog> | ||
<ignoreEOLStyle>true</ignoreEOLStyle> | ||
<skip>${skip.unit.tests}</skip> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>integration-test</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>integration-test</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- Skip dependency analysis because it's unnecessary for this module --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>${maven-dependency-plugin.version}</version> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
49 changes: 49 additions & 0 deletions
49
archetypes/archetype-lambda/src/main/resources/META-INF/maven/archetype-metadata.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="zoewanglambdatesting" | ||
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<fileSets> | ||
<fileSet filtered="true" packaged="true" encoding="UTF-8"> | ||
<directory>src/main/java</directory> | ||
<includes> | ||
<include>**/*.java</include> | ||
</includes> | ||
</fileSet> | ||
<fileSet filtered="true" packaged="true" encoding="UTF-8"> | ||
<directory>src/test/java</directory> | ||
<includes> | ||
<include>**/*.java</include> | ||
</includes> | ||
</fileSet> | ||
<fileSet filtered="true" encoding="UTF-8"> | ||
<directory/> | ||
<includes> | ||
<include>.gitignore</include> | ||
<include>template.yaml</include> | ||
<include>README.md</include> | ||
</includes> | ||
</fileSet> | ||
</fileSets> | ||
<requiredProperties> | ||
<requiredProperty key="handlerClassName"> | ||
<defaultValue>App</defaultValue> | ||
</requiredProperty> | ||
<requiredProperty key="javaSdkVersion"> | ||
<defaultValue>${project.version}</defaultValue> | ||
<validationRegex>\d+\.\d+.\d+</validationRegex> | ||
</requiredProperty> | ||
<requiredProperty key="service"> | ||
</requiredProperty> | ||
zoewangg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<requiredProperty key="httpClient"> | ||
<defaultValue>url-connection-client</defaultValue> | ||
<validationRegex>(url-connection-client|apache-client|netty-nio-client)</validationRegex> | ||
</requiredProperty> | ||
<requiredProperty key="region"> | ||
<validationRegex>^\w+-(\w+-)+\d+$</validationRegex> | ||
</requiredProperty> | ||
<!-- Required to pass the netty-open-ssl-version property from parent pom to velocity--> | ||
<requiredProperty key="nettyOpenSslVersion"> | ||
<defaultValue>${netty-open-ssl-version}</defaultValue> | ||
</requiredProperty> | ||
</requiredProperties> | ||
</archetype-descriptor> |
17 changes: 17 additions & 0 deletions
17
archetypes/archetype-lambda/src/main/resources/archetype-resources/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Eclipse | ||
.classpath | ||
.project | ||
.settings/ | ||
|
||
# Intellij | ||
.idea/ | ||
*.iml | ||
*.iws | ||
|
||
# Mac | ||
.DS_Store | ||
|
||
# Maven | ||
target/ | ||
|
||
**/dependency-reduced-pom.xml |
45 changes: 45 additions & 0 deletions
45
archetypes/archetype-lambda/src/main/resources/archetype-resources/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#[[#]]# ${handlerClassName} | ||
|
||
This project contains an AWS Lambda maven application with [AWS Java SDK 2.x](https://github.com/aws/aws-sdk-java-v2) dependencies. | ||
|
||
#[[##]]# Prerequisites | ||
- Java 1.8+ | ||
- Apache Maven | ||
- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) | ||
- Docker | ||
|
||
#[[##]]# Development | ||
|
||
The generated function handler class just returns the input. The configured AWS Java SDK client is created in `DependencyFactory` class and you can | ||
add the code to interact with the SDK client based on your use case. | ||
|
||
#[[####]]# Building the project | ||
``` | ||
mvn clean install | ||
``` | ||
|
||
#[[####]]# Testing it locally | ||
``` | ||
sam local invoke | ||
``` | ||
|
||
#[[####]]# Adding more SDK clients | ||
To add more service clients, you need to add the specific services modules in `pom.xml` and create the clients in `DependencyFactory` following the same | ||
pattern as ${serviceClientVariable}Client. | ||
|
||
#[[##]]# Deployment | ||
|
||
The generated project contains a default [SAM template](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html) file `template.yaml` where you can | ||
configure different properties of your lambda function such as memory size and timeout. You might also need to add specific policies to the lambda function | ||
so that it can access other AWS resources. | ||
|
||
To deploy the application, you can run the following command: | ||
|
||
``` | ||
sam deploy --guided | ||
``` | ||
|
||
See [Deploying Serverless Applications](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-deploying.html) for more info. | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.