Skip to content

AWS Lambda Java Sample code for using Redshift Data API

Notifications You must be signed in to change notification settings

enriquh/rs_data_api_java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

App

This project contains an AWS Lambda maven application with AWS Java SDK 2.x dependencies.

Prerequisites

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.

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)

  1. 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

  1. Add AmazonRedshiftDataFullAccess policy to the template.yaml generated by archetype to allow you to use the RS data API, more info here

  2. (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

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 redshiftDataClient.

Deployment

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.

About

AWS Lambda Java Sample code for using Redshift Data API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages