Giter Site home page Giter Site logo

atomgraph / xslttransform Goto Github PK

View Code? Open in Web Editor NEW
8.0 6.0 2.0 22 KB

XSLT transformation Lambda function for AWS Kinesis Firehose records

Home Page: https://docs.aws.amazon.com/firehose/latest/dev/data-transformation.html

License: Apache License 2.0

Java 98.41% Shell 1.59%
aws aws-lambda kinesis-firehose xslt xslt-3 transformer

xslttransform's Introduction

XSLTTransform

XSLTTransform is a generic AWS Lambda function designed specifically for Kinesis Data Firehose Data Transformation.

XSLTTransform uses Saxon-HE 9.9 processor to perform an XSLT 3.0 transformation of input records to output records. XSLT 1.0 and 2.0 stylesheets should be backwards-compatible. Naturally, the input records have to be XML. JSON can work too, if you use a 3.0 stylesheet and its JSON processing features.

Passing a map of stylesheet parameters is supported. Environment variables can be retrieved using System.getenv() and forwarded as stylesheet parameters.

Usage

The XSLT stylesheet is user-defined and has to be supplied to the function. It can be done by extending the XSLTTransform base class and overriding its constructor with stylesheet and parameter map as arguments.

The simplest way to embed a stylesheet is to put it under /src/main/resources, from where it can be read using getResourceAsStream(). That way the stylesheet is built into the function JAR itself. Alternatively, it should be possible to load it from S3.

In AWS Lambda configuration, specify transformRecords method (which is inherited by your subclass) as the function handler.

Example

The following example shows /src/main/resources/custom.xsl used as the XSLT stylesheet, as well as my-param stylesheet parameter initialized with the value of MY_PARAM environment variable.

package custom;

import com.atomgraph.etl.aws.kinesis.transform.XSLTTransform;
import java.util.Collections;
import javax.xml.transform.stream.StreamSource;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmAtomicValue;

public class CustomXSLTTransform extends XSLTTransform
{
    
    public CustomXSLTTransform() throws SaxonApiException
    {
        super(new StreamSource(CustomXSLTTransform.class.getResourceAsStream("/custom.xsl")),
            Collections.singletonMap(new QName("my-param"), new XdmAtomicValue(System.getenv("MY_PARAM"))));
    }

}

The function handler would be custom.CustomXSLTTransform::transformRecords in this case.

Build

Create a new Java project and include XSLTTransform as dependency in pom.xml:

<dependency>
    <groupId>com.atomgraph.etl.aws.kinesis</groupId>
    <artifactId>XSLTTransform</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

You might also need to add the maven-shade-plugin in the <build> section, as per Creating a .jar Deployment Package Using Maven without any IDE (Java).

Package the extended function for upload to AWS Lambda by running mvn package.

xslttransform's People

Contributors

namedgraph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.