Skip to content

Commit 22f4fb8

Browse files
committed
Add support for maven lambda archetype
1 parent 5ea0d1d commit 22f4fb8

File tree

56 files changed

+1865
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1865
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ artifact source.
1616
* [Sample Code](#sample-code)
1717
* [API Docs][docs-api]
1818
* [Developer Guide][docs-guide] ([source][docs-guide-source])
19+
* [Maven Archetypes](archetypes/README.md)
1920
* [Issues][sdk-issues]
2021
* [SDK Blog][blog]
2122
* [Giving Feedback](#giving-feedback)

archetypes/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Maven Archetypes for AWS SDK for Java 2.x
2+
3+
## Description
4+
This module contains maven archetypes for AWS Java SDK 2.x.
5+
6+
## Archetypes
7+
8+
- [archetype-lambda](archetype-lambda/README.md) - a lambda function template using AWS Java SDK 2.x
9+

archetypes/archetype-lambda/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Maven Archetype for lambda function using AWS SDK for Java 2.x
2+
3+
## Description
4+
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
5+
has the optimized configurations and follows the best practices to reduce start up time.
6+
7+
## Usage
8+
9+
You can use `mvn archetype:generate` to generate a project using this archetype. See [maven archetype usage guidance][maven-archetype-usage] for more information.
10+
11+
- Interactive mode
12+
13+
```
14+
mvn archetype:generate \
15+
-DarchetypeGroupId=software.amazon.awssdk \
16+
-DarchetypeArtifactId=archetype-lambda \
17+
-DarchetypeVersion=2.x\
18+
```
19+
20+
- Batch mode
21+
22+
```
23+
mvn archetype:generate \
24+
-DarchetypeGroupId=software.amazon.awssdk \
25+
-DarchetypeArtifactId=archetype-lambda \
26+
-DarchetypeVersion=2.x\
27+
-DgroupId=com.test \
28+
-DartifactId=sample-project \
29+
-Dservice=s3 \
30+
-Dregion=us-west-2 \
31+
-DinteractiveMode=false \
32+
```
33+
34+
### Parameters
35+
36+
Parameter Name | Default Value | Description
37+
---|---|---
38+
`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].
39+
`region` (required) | n/a | Specifies the region to be set for the SDK client in the application
40+
`groupId`(required) | n/a | Specifies the group ID of the project
41+
`artifactId`(required) | n/a | Specifies the artifact ID of the project
42+
`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]
43+
`handlerClassName` | `"App"`| Specifies the class name of the handler, which will be used as the lambda function name. It should be camel case.
44+
`javaSdkVersion` | Same version as the archetype version | Specifies the version of the AWS Java SDK 2.x to be used
45+
`version` | 1.0-SNAPSHOT | Specifies the version of the project
46+
`package` | ${groupId} | Specifies the package name for the classes
47+
48+
### Deployment
49+
50+
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
51+
configure different properties of your lambda function such as memory size and timeout.
52+
53+
```
54+
sam deploy --guided
55+
```
56+
57+
Please refer to [deploying lambda apps][deploying-lambda-apps] for more info.
58+
59+
[aws-java-sdk-v2]: https://github.com/aws/aws-sdk-java-v2
60+
[java-sdk-v2-services]: https://github.com/aws/aws-sdk-java-v2/tree/master/services
61+
[sdk-http-clients]: https://github.com/aws/aws-sdk-java-v2/tree/master/http-clients
62+
[deploying-lambda-apps]: https://docs.aws.amazon.com/lambda/latest/dg/deploying-lambda-apps.html
63+
[sam-cli]:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started.html
64+
[maven-archetype-usage]: https://maven.apache.org/archetype/maven-archetype-plugin/usage.html
65+
[sam-template]: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html

archetypes/archetype-lambda/pom.xml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License").
6+
~ You may not use this file except in compliance with the License.
7+
~ A copy of the License is located at
8+
~
9+
~ http://aws.amazon.com/apache2.0
10+
~
11+
~ or in the "license" file accompanying this file. This file is distributed
12+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
~ express or implied. See the License for the specific language governing
14+
~ permissions and limitations under the License.
15+
-->
16+
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<parent>
21+
<artifactId>archetypes</artifactId>
22+
<groupId>software.amazon.awssdk</groupId>
23+
<version>2.11.4-SNAPSHOT</version>
24+
</parent>
25+
<modelVersion>4.0.0</modelVersion>
26+
<artifactId>archetype-lambda</artifactId>
27+
<packaging>maven-archetype</packaging>
28+
<name>AWS Java SDK :: Archetype Lambda</name>
29+
<description>
30+
The AWS SDK for Java - Maven archetype for Java lambda function using AWS Java SDK 2.x
31+
</description>
32+
33+
<properties>
34+
<maven.archetype.version>3.1.2</maven.archetype.version>
35+
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
36+
</properties>
37+
38+
<dependencies>
39+
<!-- Depends on the artifacts of all services to generate serviceMapping.vm -->
40+
<dependency>
41+
<groupId>software.amazon.awssdk</groupId>
42+
<artifactId>aws-sdk-java</artifactId>
43+
<version>${awsjavasdk.version}</version>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
<build>
48+
<!-- Filtering the resource properties to get ${project.version} from archetype metadata.
49+
See https://stackoverflow.com/a/22300149 -->
50+
<resources>
51+
<resource>
52+
<directory>src/main/resources</directory>
53+
<filtering>true</filtering>
54+
<includes>
55+
<include>META-INF/maven/archetype-metadata.xml</include>
56+
</includes>
57+
</resource>
58+
<resource>
59+
<directory>src/main/resources</directory>
60+
<filtering>false</filtering>
61+
<excludes>
62+
<exclude>META-INF/maven/archetype-metadata.xml</exclude>
63+
</excludes>
64+
</resource>
65+
</resources>
66+
<extensions>
67+
<extension>
68+
<groupId>org.apache.maven.archetype</groupId>
69+
<artifactId>archetype-packaging</artifactId>
70+
<version>${maven.archetype.version}</version>
71+
</extension>
72+
</extensions>
73+
74+
<plugins>
75+
<plugin>
76+
<artifactId>exec-maven-plugin</artifactId>
77+
<groupId>org.codehaus.mojo</groupId>
78+
<version>${exec-maven-plugin.version}</version>
79+
<executions>
80+
<execution>
81+
<id>map-service-to-client-prefix</id>
82+
<phase>generate-resources</phase>
83+
<goals>
84+
<goal>exec</goal>
85+
</goals>
86+
<configuration>
87+
<executable>${basedir}/src/main/resources/map-service-to-client-prefix</executable>
88+
</configuration>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
<plugin>
93+
<artifactId>maven-archetype-plugin</artifactId>
94+
<version>${maven.archetype.version}</version>
95+
<configuration>
96+
<noLog>true</noLog>
97+
<ignoreEOLStyle>true</ignoreEOLStyle>
98+
<skip>${skip.unit.tests}</skip>
99+
</configuration>
100+
<executions>
101+
<execution>
102+
<id>integration-test</id>
103+
<phase>verify</phase>
104+
<goals>
105+
<goal>integration-test</goal>
106+
</goals>
107+
</execution>
108+
</executions>
109+
</plugin>
110+
111+
<!-- Skip dependency analysis because it's unnecessary for this module -->
112+
<plugin>
113+
<groupId>org.apache.maven.plugins</groupId>
114+
<artifactId>maven-dependency-plugin</artifactId>
115+
<version>${maven-dependency-plugin.version}</version>
116+
<configuration>
117+
<skip>true</skip>
118+
</configuration>
119+
</plugin>
120+
</plugins>
121+
</build>
122+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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"
3+
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<fileSets>
6+
<fileSet filtered="true" packaged="true" encoding="UTF-8">
7+
<directory>src/main/java</directory>
8+
<includes>
9+
<include>**/*.java</include>
10+
</includes>
11+
</fileSet>
12+
<fileSet filtered="true" packaged="true" encoding="UTF-8">
13+
<directory>src/test/java</directory>
14+
<includes>
15+
<include>**/*.java</include>
16+
</includes>
17+
</fileSet>
18+
<fileSet filtered="true" encoding="UTF-8">
19+
<directory/>
20+
<includes>
21+
<include>.gitignore</include>
22+
<include>template.yaml</include>
23+
<include>README.md</include>
24+
</includes>
25+
</fileSet>
26+
</fileSets>
27+
<requiredProperties>
28+
<requiredProperty key="handlerClassName">
29+
<defaultValue>App</defaultValue>
30+
</requiredProperty>
31+
<requiredProperty key="javaSdkVersion">
32+
<defaultValue>${project.version}</defaultValue>
33+
<validationRegex>\d+\.\d+.\d+</validationRegex>
34+
</requiredProperty>
35+
<requiredProperty key="service">
36+
</requiredProperty>
37+
<requiredProperty key="httpClient">
38+
<defaultValue>url-connection-client</defaultValue>
39+
<validationRegex>(url-connection-client|apache-client|netty-nio-client)</validationRegex>
40+
</requiredProperty>
41+
<requiredProperty key="region">
42+
<validationRegex>^\w+-(\w+-)+\d+$</validationRegex>
43+
</requiredProperty>
44+
<!-- Required to pass the netty-open-ssl-version property from parent pom to velocity-->
45+
<requiredProperty key="nettyOpenSslVersion">
46+
<defaultValue>${netty-open-ssl-version}</defaultValue>
47+
</requiredProperty>
48+
</requiredProperties>
49+
</archetype-descriptor>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Eclipse
2+
.classpath
3+
.project
4+
.settings/
5+
6+
# Intellij
7+
.idea/
8+
*.iml
9+
*.iws
10+
11+
# Mac
12+
.DS_Store
13+
14+
# Maven
15+
target/
16+
17+
**/dependency-reduced-pom.xml
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#[[#]]# ${handlerClassName}
2+
3+
This project contains an AWS Lambda maven application with [AWS Java SDK 2.x](https://github.com/aws/aws-sdk-java-v2) dependencies.
4+
5+
#[[##]]# Prerequisites
6+
- Java 1.8+
7+
- Apache Maven
8+
- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
9+
- Docker
10+
11+
#[[##]]# Development
12+
13+
The generated function handler class just returns the input. The configured AWS Java SDK client is created in `DependencyFactory` class and you can
14+
add the code to interact with the SDK client based on your use case.
15+
16+
#[[####]]# Building the project
17+
```
18+
mvn clean install
19+
```
20+
21+
#[[####]]# Testing it locally
22+
```
23+
sam local invoke
24+
```
25+
26+
#[[####]]# Adding more SDK clients
27+
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
28+
pattern as ${serviceClientVariable}Client.
29+
30+
#[[##]]# Deployment
31+
32+
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
33+
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
34+
so that it can access other AWS resources.
35+
36+
To deploy the application, you can run the following command:
37+
38+
```
39+
sam deploy --guided
40+
```
41+
42+
See [Deploying Serverless Applications](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-deploying.html) for more info.
43+
44+
45+

0 commit comments

Comments
 (0)