| Layer | Name | Description | Client |
|---|---|---|---|
| 1 | Docker | Cloud VM (EC2) running the pandoc docker container | EC2 command line |
| 2 | Python | Python subprocess that invokes Layer 1 command line | Python script on EC2 host |
| 3 | XMLRPC | XMLRPC server (python script) that listens to requests on port 8001 and calls Layer 2 script | Remote Python client |
| 4 | Lambda | Lambda function that implements the XMLRPC client and listens for HTTP POST requests | curl |
| 5 | Web | Static web application hosted on S3 that uses an AJAX request to call the Lambda URL | Web browser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use root/example as user/password credentials | |
| version: '3.1' | |
| services: | |
| db: | |
| image: mysql:5.7 | |
| command: --default-authentication-plugin=mysql_native_password | |
| restart: always | |
| environment: | |
| MYSQL_ROOT_PASSWORD: SET_YOUR_LONG_COMPLEX_PASSWORD_HERE | |
| ports: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function base64ToArrayBuffer(base64) { | |
| var binaryString = window.atob(base64); | |
| var binaryLen = binaryString.length; | |
| var bytes = new Uint8Array(binaryLen); | |
| for (var i = 0; i < binaryLen; i++) { | |
| var ascii = binaryString.charCodeAt(i); | |
| bytes[i] = ascii; | |
| } | |
| return bytes; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
| <meta name="description" content="Document Converter"> | |
| <meta name="author" content="Vijay Balasubramaniam"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from chalice import Chalice, Response | |
| from chalicelib import l3_xmlrpc_client as c | |
| import sys, base64, json | |
| app = Chalice(app_name='l4_lambda') | |
| @app.route('/convert/{convert_from}/to/{convert_to}', methods=['POST'], | |
| content_types=['application/octet-stream'], cors=True) | |
| def pandoc_convert(convert_from, convert_to): | |
| out = c.convert(convert_from, convert_to, app.current_request.raw_body) | |
| obj = {'data': base64.b64encode(out).decode()} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def convert(convert_from, convert_to, source_data): | |
| import xmlrpc.client | |
| import sys, base64 | |
| s = xmlrpc.client.ServerProxy('http://54.209.175.70:8001', allow_none=True, use_builtin_types=True) | |
| #s = xmlrpc.client.ServerProxy('http://127.0.0.1:8001', allow_none=True, use_builtin_types=True) | |
| (out, err) = s.run_pandoc(convert_from, convert_to, base64.encodebytes(source_data)) | |
| print(err, file=sys.stderr) | |
| return out | |
| import sys | |
| if __name__ == '__main__': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from xmlrpc.server import SimpleXMLRPCServer | |
| from xmlrpc.server import SimpleXMLRPCRequestHandler | |
| # Restrict to a particular path. | |
| class RequestHandler(SimpleXMLRPCRequestHandler): | |
| rpc_paths = ('/RPC2',) | |
| # Create server | |
| with SimpleXMLRPCServer(('0.0.0.0', 8001), requestHandler=RequestHandler, allow_none=True, use_builtin_types=True) as server: | |
| server.register_introspection_functions() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def docker_run(args): | |
| import subprocess | |
| cmd = ["docker", "run", "--rm"] | |
| cmd.extend(args) | |
| cp = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) | |
| out = cp.stdout; err = cp.stderr | |
| return (out, err) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os, sys, base64, uuid | |
| def run_pandoc(format_from, format_to, b64data): | |
| data = base64.decodebytes(b64data) | |
| from docker_run import docker_run | |
| filename = 'temp/'+str(uuid.uuid4()).replace('-', '') | |
| with open(filename, 'wb') as f: | |
| f.write(data) | |
| (out, err) = docker_run(["-v", os.getcwd()+":/source", "jagregory/pandoc", "-f", format_from, "-t", format_to, "-o", "/dev/stdout", filename]) | |
| os.remove(filename) | |
| sys.stderr.buffer.write(err) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sudo docker run -i --rm -v $(pwd):/source jagregory/pandoc -f $1 -t $2 -o /dev/stdout $3 | |
| #SYNTAX: ./l1_run.sh {FROM} {TO} {INPUT_FILE} >{OUTPUT_FILE} | |
| #EXAMPLE: ./l1_run.sh markdown docx README.md >README.docx |