This project contains an AWS Lambda maven application with AWS Java SDK 2.x dependencies.
- Java 1.8+
- Apache Maven
- AWS SAM CLI
- Docker
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.
In order to generate this project the following steps were performed (notice that you need to comply with the pre-requisites before performing these steps)
- Generate project using mvn archetype:
mvn -B archetype:generate -DarchetypeGroupId=software.amazon.awssdk -DarchetypeArtifactId=archetype-lambda -Dservice=redshiftdata -Dregion=US_EAST_1 -DgroupId=com.example.myapp -DartifactId=myapp
Note the -Dservice=redshiftdata and -Dregion=US_EAST_1 options, replace it by the appropriate region as needed, supported services for archetype can be found here
-
Add AmazonRedshiftDataFullAccess policy to the template.yaml generated by archetype to allow you to use the RS data API, more info here
-
(optional) Add the maven-jar-plugin to the project POM if you want to be able to execute the JAR locally (to specify Mainclass), more info here
mvn clean install
sam local invoke
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 redshiftDataClient.
The generated project contains a default SAM template 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
You will need to provide the following parameters:
- ARN of the AWS Secret Manager secret containing the username and password for your redshift cluster id
See Deploying Serverless Applications for more info.