Skip to content

Commit b510c1f

Browse files
committed
Update/add more docs, add netty openssl dependencies
1 parent 31a5b3a commit b510c1f

File tree

18 files changed

+248
-20
lines changed

18 files changed

+248
-20
lines changed

archetypes/archetype-lambda/src/main/resources/META-INF/maven/archetype-metadata.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<includes>
2121
<include>.gitignore</include>
2222
<include>template.yaml</include>
23+
<include>README.md</include>
2324
</includes>
2425
</fileSet>
2526
</fileSets>
@@ -40,5 +41,9 @@
4041
<requiredProperty key="region">
4142
<validationRegex>^\w+-(\w+-)+\d+$</validationRegex>
4243
</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>
4348
</requiredProperties>
4449
</archetype-descriptor>
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+

archetypes/archetype-lambda/src/main/resources/archetype-resources/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<aws.java.sdk.version>${javaSdkVersion}</aws.java.sdk.version>
3232
<aws.lambda.java.version>1.2.0</aws.lambda.java.version>
3333
<junit5.version>5.4.2</junit5.version>
34+
#if( $httpClient == 'netty-nio-client')
35+
<netty.openssl.version>${nettyOpenSslVersion}</netty.openssl.version>
36+
#end
3437
</properties>
3538

3639
<dependencyManagement>
@@ -66,6 +69,15 @@
6669
<artifactId>${httpClient}</artifactId>
6770
</dependency>
6871

72+
#if( $httpClient == 'netty-nio-client')
73+
<!-- Adding netty-tcnative dependency so that netty async client uses openSSL as sslProvider if supported
74+
See https://github.com/aws/aws-sdk-java-v2/blob/master/docs/BestPractices.md#use-openssl-for-netty-async-client -->
75+
<dependency>
76+
<groupId>io.netty</groupId>
77+
<artifactId>netty-tcnative-boringssl-static</artifactId>
78+
<version>${netty.openssl.version}</version>
79+
</dependency>
80+
#end
6981
<dependency>
7082
<groupId>com.amazonaws</groupId>
7183
<artifactId>aws-lambda-java-core</artifactId>

archetypes/archetype-lambda/src/main/resources/archetype-resources/src/main/java/DependencyFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private DependencyFactory() {}
1717
/**
1818
* @return an instance of ${serviceClientClassName}
1919
*/
20-
public static ${serviceClientClassName} ${service}Client() {
20+
public static ${serviceClientClassName} ${serviceClientVariable}Client() {
2121
return ${serviceClientClassName}.builder()
2222
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
2323
.region(Region.${regionEnum})

archetypes/archetype-lambda/src/main/resources/archetype-resources/src/main/java/__handlerClassName__.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
* @see <a href=https://docs.aws.amazon.com/lambda/latest/dg/java-handler.html>Lambda Java Handler</a> for more information
1313
*/
1414
public class ${handlerClassName} implements RequestHandler<Object, Object> {
15-
private final ${serviceClientClassName} ${service}Client;
15+
private final ${serviceClientClassName} ${serviceClientVariable}Client;
1616

1717
public ${handlerClassName}() {
1818
// Initialize the SDK client outside of the handler method so that it can be reused for subsequent invocations.
1919
// It is initialized when the class is loaded.
20-
${service}Client = DependencyFactory.${service}Client();
20+
${serviceClientVariable}Client = DependencyFactory.${serviceClientVariable}Client();
2121
// Consider invoking a simple api here to pre-warm up the application, eg: dynamodb#listTables
2222
}
2323

2424
@Override
2525
public Object handleRequest(final Object input, final Context context) {
26-
// TODO: invoking the api call using ${service}Client.
26+
// TODO: invoking the api call using ${serviceClientVariable}Client.
2727
return input;
2828
}
2929
}

archetypes/archetype-lambda/src/main/resources/archetype-resources/template.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ Resources:
1010
Handler: ${package}.${handlerClassName}::handleRequest
1111
Timeout: 60
1212
MemorySize: 512
13-
CodeUri: ./target/${artifactId}.jar
13+
CodeUri: ./target/${artifactId}.jar
14+
# Attach policies here to give the function permission to access other AWS resources if needed
15+
# See: https://github.com/awslabs/serverless-application-model/blob/master/docs/policy_templates.rst
16+
# eg:
17+
#Policies:
18+
# - S3ReadPolicy:
19+
# BucketName: test-bucket
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
## global variables used by the project
2+
#parse ("serviceMapping.vm")
23
#set( $symbol_pound = '#' )
34
#set( $symbol_dollar = '$' )
45
#set( $symbol_escape = '\' )
5-
## TODO: there is no easy way to map service module artifactId to the client name derived the service name
6-
## As a workaround: mapping the common service here
7-
#if( $service == 'dynamodb')
8-
#set ( $service = 'dynamoDb')
9-
#end
10-
#set ( $servicePackage = $service.toLowerCase())
11-
#set( $serviceClientPrefix = $service.substring(0,1).toUpperCase() + $service.substring(1))
6+
## map the serviceId to service package and service client class name
7+
#set ( $servicePackage = $service)
8+
#set( $serviceClientPrefix = $serviceMapping[$service])
9+
#set ( $serviceClientVariable = $serviceClientPrefix.substring(0,1).toLowerCase() + $serviceClientPrefix.substring(1))
1210
#set( $regionEnum = $region.replace("-", "_").toUpperCase() )
1311
## map the client module name to the client class name and pacakge name
1412
#if( $httpClient == 'url-connection-client')
@@ -24,6 +22,3 @@
2422
#set ($httpClientPackageName = 'nio.netty.' + $httpClientClassName)
2523
#set ($serviceClientClassName = $serviceClientPrefix + 'AsyncClient')
2624
#end
27-
## map the serviceId to service package and service client class name
28-
#set( $servicePackage = $service.toLowerCase())
29-
#set( $serviceClientPrefix = $service.substring(0,1).toUpperCase() + $service.substring(1))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#set ( $serviceMapping ={"detective": "Detective", "efs": "Efs", "shield": "Shield", "connectparticipant": "ConnectParticipant", "datapipeline": "DataPipeline", "kafka": "Kafka", "appstream": "AppStream", "dlm": "Dlm", "pinpointemail": "PinpointEmail", "glue": "Glue", "route53": "Route53", "sesv2": "SesV2", "storagegateway": "StorageGateway", "ses": "Ses", "resourcegroupstaggingapi": "ResourceGroupsTaggingApi", "personalizeruntime": "PersonalizeRuntime", "alexaforbusiness": "AlexaForBusiness", "qldb": "Qldb", "cloud9": "Cloud9", "appmesh": "AppMesh", "dynamodb": "DynamoDb", "cloudhsmv2": "CloudHsmV2", "elasticbeanstalk": "ElasticBeanstalk", "cognitosync": "CognitoSync", "marketplaceentitlement": "MarketplaceEntitlement", "health": "Health", "kinesisvideo": "KinesisVideo", "cognitoidentity": "CognitoIdentity", "cloudwatchlogs": "CloudWatchLogs", "securityhub": "SecurityHub", "kinesis": "Kinesis", "polly": "Polly", "datasync": "DataSync", "autoscaling": "AutoScaling", "pinpointsmsvoice": "PinpointSmsVoice", "ssm": "Ssm", "sso": "Sso", "transcribestreaming": "TranscribeStreaming", "kinesisanalyticsv2": "KinesisAnalyticsV2", "dax": "Dax", "ssooidc": "SsoOidc", "apigateway": "ApiGateway", "medialive": "MediaLive", "groundstation": "GroundStation", "lexruntime": "LexRuntime", "snowball": "Snowball", "appconfig": "AppConfig", "mediaconvert": "MediaConvert", "macie": "Macie", "marketplacecatalog": "MarketplaceCatalog", "secretsmanager": "SecretsManager", "emr": "Emr", "iot1clickdevices": "Iot1ClickDevices", "dataexchange": "DataExchange", "forecastquery": "Forecastquery", "opsworks": "OpsWorks", "iotthingsgraph": "IoTThingsGraph", "imagebuilder": "Imagebuilder", "mediapackage": "MediaPackage", "lightsail": "Lightsail", "xray": "XRay", "migrationhub": "MigrationHub", "connect": "Connect", "ebs": "Ebs", "qldbsession": "QldbSession", "iotevents": "IotEvents", "computeoptimizer": "ComputeOptimizer", "appsync": "AppSync", "iot1clickprojects": "Iot1ClickProjects", "pinpoint": "Pinpoint", "workdocs": "WorkDocs", "cloudwatchevents": "CloudWatchEvents", "sms": "Sms", "cloudwatch": "CloudWatch", "forecast": "Forecast", "route53domains": "Route53Domains", "kms": "Kms", "budgets": "Budgets", "applicationdiscovery": "ApplicationDiscovery", "sts": "Sts", "applicationautoscaling": "ApplicationAutoScaling", "personalize": "Personalize", "robomaker": "RoboMaker", "databasemigration": "DatabaseMigration", "frauddetector": "FraudDetector", "guardduty": "GuardDuty", "comprehendmedical": "ComprehendMedical", "ecs": "Ecs", "ecr": "Ecr", "codebuild": "CodeBuild", "directconnect": "DirectConnect", "mediastore": "MediaStore", "opsworkscm": "OpsWorksCm", "codestar": "CodeStar", "rds": "Rds", "gamelift": "GameLift", "quicksight": "QuickSight", "mediapackagevod": "MediaPackageVod", "firehose": "Firehose", "elasticsearch": "Elasticsearch", "outposts": "Outposts", "waf": "Waf", "licensemanager": "LicenseManager", "networkmanager": "NetworkManager", "elasticache": "ElastiCache", "eks": "Eks", "support": "Support", "kinesisvideoarchivedmedia": "KinesisVideoArchivedMedia", "lambda": "Lambda", "devicefarm": "DeviceFarm", "backup": "Backup", "redshift": "Redshift", "codegurureviewer": "CodeGuruReviewer", "cloudformation": "CloudFormation", "autoscalingplans": "AutoScalingPlans", "mediaconnect": "MediaConnect", "transcribe": "Transcribe", "textract": "Textract", "chime": "Chime", "iotdataplane": "IotDataPlane", "comprehend": "Comprehend", "iotanalytics": "IoTAnalytics", "iam": "Iam", "costexplorer": "CostExplorer", "eventbridge": "EventBridge", "importexport": "ImportExport", "machinelearning": "MachineLearning", "s3control": "S3Control", "transfer": "Transfer", "resourcegroups": "ResourceGroups", "serverlessapplicationrepository": "ServerlessApplicationRepository", "fms": "Fms", "ioteventsdata": "IotEventsData", "swf": "Swf", "kinesisvideosignaling": "KinesisVideoSignaling", "cloudsearchdomain": "CloudSearchDomain", "workmailmessageflow": "WorkMailMessageFlow", "acmpca": "AcmPca", "servicediscovery": "ServiceDiscovery", "rdsdata": "RdsData", "translate": "Translate", "athena": "Athena", "applicationinsights": "ApplicationInsights", "lexmodelbuilding": "LexModelBuilding", "ec2instanceconnect": "Ec2InstanceConnect", "codeguruprofiler": "CodeGuruProfiler", "mturk": "MTurk", "cloudfront": "CloudFront", "ec2": "Ec2", "sagemakera2iruntime": "SageMakerA2IRuntime", "route53resolver": "Route53Resolver", "managedblockchain": "ManagedBlockchain", "kinesisanalytics": "KinesisAnalytics", "kendra": "Kendra", "codepipeline": "CodePipeline", "elastictranscoder": "ElasticTranscoder", "organizations": "Organizations", "pi": "Pi", "servicecatalog": "ServiceCatalog", "apigatewayv2": "ApiGatewayV2", "servicequotas": "ServiceQuotas", "marketplacemetering": "MarketplaceMetering", "batch": "Batch", "codecommit": "CodeCommit", "mq": "Mq", "iotsecuretunneling": "IoTSecureTunneling", "costandusagereport": "CostAndUsageReport", "signer": "Signer", "migrationhubconfig": "MigrationHubConfig", "codestarnotifications": "CodestarNotifications", "elasticloadbalancing": "ElasticLoadBalancing", "pricing": "Pricing", "kinesisvideomedia": "KinesisVideoMedia", "rekognition": "Rekognition", "cloudtrail": "CloudTrail", "elasticloadbalancingv2": "ElasticLoadBalancingV2", "personalizeevents": "PersonalizeEvents", "ram": "Ram", "mediatailor": "MediaTailor", "cloudhsm": "CloudHsm", "apigatewaymanagementapi": "ApiGatewayManagementApi", "cloudsearch": "CloudSearch", "acm": "Acm", "inspector": "Inspector", "lakeformation": "LakeFormation", "elasticinference": "ElasticInference", "schemas": "Schemas", "amplify": "Amplify", "globalaccelerator": "GlobalAccelerator", "s3": "S3", "clouddirectory": "CloudDirectory", "accessanalyzer": "AccessAnalyzer", "greengrass": "Greengrass", "worklink": "WorkLink", "sagemaker": "SageMaker", "config": "Config", "workspaces": "WorkSpaces", "savingsplans": "Savingsplans", "sqs": "Sqs", "iot": "Iot", "codestarconnections": "CodeStarConnections", "sfn": "Sfn", "directory": "Directory", "marketplacecommerceanalytics": "MarketplaceCommerceAnalytics", "sns": "Sns", "mediastoredata": "MediaStoreData", "workmail": "WorkMail", "cognitoidentityprovider": "CognitoIdentityProvider", "codedeploy": "CodeDeploy", "iotjobsdataplane": "IotJobsDataPlane", "mobile": "Mobile", "docdb": "DocDb", "neptune": "Neptune", "wafv2": "Wafv2", "glacier": "Glacier", "fsx": "FSx", "sagemakerruntime": "SageMakerRuntime"})

archetypes/archetype-lambda/src/test/resources/projects/apachehttpclient/archetype.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ service=dynamodb
66
httpClient=apache-client
77
handlerClassName=MyApacheFunction
88
region=ap-southeast-1
9-
javaSdkVersion=2.11.0
9+
javaSdkVersion=2.11.0
10+
nettyOpenSslVersion=2.0.29.Final
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# MyApacheFunction
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 dynamoDbClient.
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+

archetypes/archetype-lambda/src/test/resources/projects/apachehttpclient/reference/template.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ Resources:
1010
Handler: software.amazonaws.test.MyApacheFunction::handleRequest
1111
Timeout: 60
1212
MemorySize: 512
13-
CodeUri: ./target/test-apache-artifact.jar
13+
CodeUri: ./target/test-apache-artifact.jar
14+
# Attach policies here to give the function permission to access other AWS resources if needed
15+
# See: https://github.com/awslabs/serverless-application-model/blob/master/docs/policy_templates.rst
16+
# eg:
17+
#Policies:
18+
# - S3ReadPolicy:
19+
# BucketName: test-bucket

archetypes/archetype-lambda/src/test/resources/projects/nettyclient/archetype.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ httpClient=netty-nio-client
77
handlerClassName=MyNettyFunction
88
region=us-east-1
99
javaSdkVersion=2.11.0
10+
nettyOpenSslVersion=2.0.29.Final
1011

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# MyNettyFunction
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 kinesisClient.
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+

archetypes/archetype-lambda/src/test/resources/projects/nettyclient/reference/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<aws.java.sdk.version>2.11.0</aws.java.sdk.version>
3232
<aws.lambda.java.version>1.2.0</aws.lambda.java.version>
3333
<junit5.version>5.4.2</junit5.version>
34+
<netty.openssl.version>2.0.29.Final</netty.openssl.version>
3435
</properties>
3536

3637
<dependencyManagement>
@@ -66,6 +67,13 @@
6667
<artifactId>netty-nio-client</artifactId>
6768
</dependency>
6869

70+
<!-- Adding netty-tcnative dependency so that netty async client uses openSSL as sslProvider if supported
71+
See https://github.com/aws/aws-sdk-java-v2/blob/master/docs/BestPractices.md#use-openssl-for-netty-async-client -->
72+
<dependency>
73+
<groupId>io.netty</groupId>
74+
<artifactId>netty-tcnative-boringssl-static</artifactId>
75+
<version>${netty.openssl.version}</version>
76+
</dependency>
6977
<dependency>
7078
<groupId>com.amazonaws</groupId>
7179
<artifactId>aws-lambda-java-core</artifactId>

archetypes/archetype-lambda/src/test/resources/projects/nettyclient/reference/template.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ Resources:
1010
Handler: software.amazonaws.test.MyNettyFunction::handleRequest
1111
Timeout: 60
1212
MemorySize: 512
13-
CodeUri: ./target/test-netty-artifact.jar
13+
CodeUri: ./target/test-netty-artifact.jar
14+
# Attach policies here to give the function permission to access other AWS resources if needed
15+
# See: https://github.com/awslabs/serverless-application-model/blob/master/docs/policy_templates.rst
16+
# eg:
17+
#Policies:
18+
# - S3ReadPolicy:
19+
# BucketName: test-bucket

archetypes/archetype-lambda/src/test/resources/projects/urlhttpclient/archetype.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ service=s3
66
httpClient=url-connection-client
77
handlerClassName=App
88
region=us-west-2
9-
javaSdkVersion=2.11.0
9+
javaSdkVersion=2.11.0
10+
nettyOpenSslVersion=2.0.29.Final

0 commit comments

Comments
 (0)