Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For example, this would load the module with the alias AWSS3:

 

Code Block
languagejavascript
use module a41x174 alias AWSS3

...


   with AWSKeys = keys:aws() 

 

When loading the module, be sure to define your AWS keys in the meta block. There are two required keys, and should be defined like so:

 

Code Block
languagejavascript
key aws {

...


   "AWSAccessKey": "

...

YOURACCESSKEYHERE",

...


   "AWSSecretKey": "

...

YOURSECRETKEYHERE"
}

 

 

The Amazon S3 Module provides two functions and one actions.

...

getValue returns the base64 encoded value of the data URI. In other words, it strips out the "data:<mimetype>;base64," and returns the actual data.

 

Code Block
languagejavascript
rule getValue is active {

...


   select when pageview ".*" setting ()

...


   pre {
      image = <<data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==>>;

...


      base64EncodedData = AWSS3:getValue(image);

...


      // Evaluates to iVBORw0KGgoAAAA...

...


   

...

}

...


   noop();
}

...

 

getType function

getType takes one parameter. This parameter type is a string encoded as a Data URI.

getType performs the exact opposite operation of getValue. Instead of returning the base64 encoded data, getType returns the mimetype of the data URI encoded data.

 

Code Block
languagejavascript
rule 

...

getType is active {

...


   select when pageview ".*" setting ()

...


   pre {
      image = <<data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==>>;

...


      mimetype = AWSS3:getType(image);

...


      // Evaluates to image/png
   }
   noop();
}

 

upload action

The upload action is currently the only action available in the Amazon S3 Module. It takes three parameters, the bucket, the object_name and the object_value.

The bucket is a string. This string should contain the name of the Amazon S3 bucket to upload your file to.

The object_name is a string. This string is the name to upload your file as.

The object_value is the value of the file to upload.

As well as having these three parameters, you can also configure the upload action with the following options:

  • object_type
    • This option is the mimetype of the file you are uploading.

 

...

upload action

The upload action 

Code Block
languagejavascript
rule upload is active {
   select when pageview ".*" setting ()
   pre {
      text = "This is a test upload";
   }
   {
      AWSS3:upload("kynetx_example", "kynetx_example_upload.txt", text);
   }
}

 

Example Ruleset

Code Block
languagejavascript
ruleset a41x175 {
	meta {
		name "TestAmazonS3Module"
		description <<
			TestAmazonS3Module
		>>
		author "Jessie A. Morris"
		// Uncomment this line to require Marketplace purchase to use this app.
		// authz require user
		logging on
		
		key aws {
		   "AWSAccessKey": "YOURACCESSKEYHERE",
		   "AWSSecretKey": "YOURSECRETKEYHERE"
		}

		use module a41x174 alias AWSS3
			with AWSKeys = keys:aws()
	}
	dispatch {
		// Some example dispatch domains
		// domain "example.com"
		// domain "other.example.com"
	}
	global {
		image = <<data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==>>;
	}
	rule getValue is active {
		select when pageview ".*" setting ()
		pre {
			image = <<data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==>>;
			base64EncodedData = AWSS3:getValue(image);
		}
		noop();
	}
	rule getType is active {
		select when pageview ".*" setting ()
		pre {
			image = <<data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==>>;
			mimetype = AWSS3:getType(image);
		}
		noop();
	}
	rule upload is active {
		select when pageview ".*" setting ()
		pre {
			text = "This is a test upload";
		}
		{
AWSS3:upload("kynetx_example", "kynetx_example_upload.txt", text);
		}
	}
}