Writing CFML wrappers for the AWS Java SDK is time consuming and results in verbose, hard to read code. It's not fun reading the java docs and trying to figure out how to wire it all together.

A much simpler way to interact with AWS in Lucee is using the AWS Command Line Interface (AWS CLI).

Get the AWS CLI

If your Lucee server is running on an AWS instance launched from the official Amazon Linux AMI then it already has the AWS CLI installed. If not, don't worry, it's easy to install.

"The primary distribution method for the AWS CLI on Linux, Windows, and macOS is pip, a package manager for Python that provides an easy way to install, upgrade, and remove Python packages and their dependencies."

For installation instructions see ... Installing the AWS Command Line Interface.

Setup the environment

In order to run commands and manage your AWS services using the CLI you'll need to setup some environment variables. You really only need to setup variables for the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

My Lucee install path is /opt/lucee (your installation path may vary).

You'll need to add your AWS access keys as environment variables in the file:

/opt/lucee/tomcat/bin/setenv.sh

Add these 4 lines to your setenv.sh file. Replace my dummy values with your actual keys.

AWS_ACCESS_KEY_ID="ABCDEFGHIJKLMNOPQRST";
AWS_SECRET_ACCESS_KEY="1234567890abcdefghijklmnopqrstuvwxyz1234";

export AWS_ACCESS_KEY_ID;
export AWS_SECRET_ACCESS_KEY;

aws-cli-env

Then restart Lucee

/opt/lucee/lucee_ctl restart

Run AWS CLI commands with cfexecute

Here's some quick sample code to get you started.

<cfscript>

cfexecute(variable="cli_output",name="/usr/bin/aws",arguments="--region us-east-1 ec2 describe-instances",timeout=10);

if (isJson(cli_output)) {
    dump(deserializeJson(cli_output));
} else {
    dump(cli_output)
}

</cfscript>

Next Step

Lookup your desired commands in the AWS CLI Reference and modify the cfexecute command above as needed.

Happy Coding